pub trait GetSize {
    const CAPACITY: Option<usize>;

    // Required methods
    fn get_size(&self) -> usize;
    fn is_full(&self) -> bool;

    // Provided method
    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 Associated Constants§

source

const CAPACITY: Option<usize>

Get the max size that this data structure can acommodate.

Required Methods§

source

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

fn is_full(&self) -> bool

Is there no room left in this collection?

use toad_common::GetSize;

let array = tinyvec::ArrayVec::<[u8; 2]>::from([1, 2]);

assert!(array.is_full())

Provided Methods§

source

fn size_is_zero(&self) -> bool

Check if the runtime size is zero

use toad_common::GetSize;

assert!(Vec::<u8>::new().size_is_zero())

Implementations on Foreign Types§

source§

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

source§

const CAPACITY: Option<usize> = None

source§

fn get_size(&self) -> usize

source§

fn is_full(&self) -> bool

source§

impl<T> GetSize for Vec<T>

source§

const CAPACITY: Option<usize> = None

source§

fn get_size(&self) -> usize

source§

fn is_full(&self) -> bool

source§

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

source§

const CAPACITY: Option<usize> = None

source§

fn get_size(&self) -> usize

source§

fn is_full(&self) -> bool

source§

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

Implementors§