Trait toad_common::array::GetSize
source · [−]pub trait GetSize {
fn get_size(&self) -> usize;
fn max_size(&self) -> Option<usize>;
fn is_full(&self) -> bool;
fn size_is_zero(&self) -> bool { ... }
}Expand description
Get the runtime size of some data structure
Deprecated
Note: in a future version of toad_common this will be deprecated in favor of clearly delineating
“size in bytes” (e.g. RuntimeSize) from “collection of potentially bounded length” (e.g. Len)
Collections
For collections this just yields the number of elements (Vec::len, tinyvec::ArrayVec::len),
and when the collection is over u8s,
then get_size represents the number of bytes in the collection.
Structs and enums
When implemented for items that are not collections,
this is expected to yield the runtime size in bytes
(not the static Rust core::mem::size_of size)
Required Methods
sourcefn get_size(&self) -> usize
fn get_size(&self) -> usize
Get the runtime size (in bytes) of a struct
For collections this is always equivalent to calling an inherent len method.
use toad_common::GetSize;
assert_eq!(vec![1u8, 2].get_size(), 2)sourcefn max_size(&self) -> Option<usize>
fn max_size(&self) -> Option<usize>
Get the max size that this data structure can acommodate.
By default, this returns None and can be left unimplemented for dynamic collections.
However, for fixed-size collections this method must be implemented.
use toad_common::GetSize;
let stack_nums = tinyvec::ArrayVec::<[u8; 2]>::from([0, 1]);
assert_eq!(stack_nums.max_size(), Some(2));Provided Methods
sourcefn size_is_zero(&self) -> bool
fn size_is_zero(&self) -> bool
Check if the runtime size is zero
use toad_common::GetSize;
assert!(Vec::<u8>::new().size_is_zero())