Len

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

Required Associated Constants§

Source

const CAPACITY: Option<usize>

The maximum number of elements that this data structure can acommodate.

Required Methods§

Source

fn len(&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_len::Len;

assert_eq!(Len::len(&vec![1u8, 2]), 2)
Source

fn is_full(&self) -> bool

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))

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if the runtime size is zero

use toad_len::Len;

assert!(Len::is_empty(&Vec::<u8>::new()))

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<A: Array> Len for ArrayVec<A>

Source§

impl<K, V> Len for BTreeMap<K, V>

Available on crate feature alloc only.
Source§

const CAPACITY: Option<usize> = None

Source§

fn len(&self) -> usize

Source§

fn is_full(&self) -> bool

Source§

impl<K: Eq + Hash, V> Len for HashMap<K, V>

Available on crate feature std only.
Source§

const CAPACITY: Option<usize> = None

Source§

fn len(&self) -> usize

Source§

fn is_full(&self) -> bool

Source§

impl<T> Len for Vec<T>

Available on crate feature alloc only.
Source§

const CAPACITY: Option<usize> = None

Source§

fn len(&self) -> usize

Source§

fn is_full(&self) -> bool

Implementors§