Add `size_in_bytes`
@@ -251,6 +251,14 @@ impl<T, const N: usize> StaticVec<T, N> {
N - self.length
}
+ /// Returns the total size of the inhabited part of StaticVec (which may be zero if it has a
+ /// length of zero) in bytes. Specifically, the return value of this function amounts to
+ /// a calculation of `size_of::<T>() * self.length`.
+ #[inline(always)]
+ pub const fn size_in_bytes(&self) -> usize {
+ intrinsics::size_of::<T>() * self.length
+ }
+
/// Directly sets the length field of the StaticVec to `new_len`. Useful if you intend
/// to write to it solely element-wise, but marked unsafe due to how it creates
/// the potential for reading from uninitialized memory later on.
