Trait Len
Source pub trait Len {
const CAPACITY: Option<usize>;
// Required methods
fn len(&self) -> usize;
fn is_full(&self) -> bool;
// Provided method
fn is_empty(&self) -> bool { ... }
}
Expand description
Get the runtime size of some data structure
The maximum number of elements that this data structure can acommodate.
Get the runtime size (in bytes) of a struct
For collections this is always equivalent to calling an inherent len method.
use toad_len::Len;
assert_eq!(Len::len(&vec![1u8, 2]), 2)
Is there no room left in this collection?
use toad_len::Len;
let array = tinyvec::ArrayVec::<[u8; 2]>::from([1, 2]);
assert!(Len::is_full(&array))
Check if the runtime size is zero
use toad_len::Len;
assert!(Len::is_empty(&Vec::<u8>::new()))
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Source§Available on crate feature alloc only.
Source§Available on crate feature std only.
Source§Available on crate feature alloc only.