Skip to main content

HasMemoryCostStructural

Trait HasMemoryCostStructural 

Source
pub trait HasMemoryCostStructural {
    // Required method
    fn indirect_memory_cost(&self, _: EnabledToken) -> usize;
}
Expand description

Types whose HasMemoryCost is derived structurally

Usually implemented using #[derive_deftly(HasMemoryCost)].

For Copy types, it can also be implemented with memory_cost_structural_copy!.

When this trait is implemented, a blanket impl provides HasMemoryCost.

§Structural memory cost

We call the memory cost “structural” when it is derived from the type’s structure.

The memory cost of a HasMemoryCostStructural type is:

  • The number of bytes in its own size size_of; plus

  • The (structural) memory cost of all the out-of-line data that it owns; that’s what’s returned by indirect_memory_cost

For example, Strings out-of-line memory cost is just its capacity, so its memory cost is the size of its three word layout plus its capacity.

This calculation is performed by the blanket impl of HasMemoryCost.

§Shared data - non-'static types, Arc

It is probably a mistake to implement this trait (or HasMemoryCost) for types with out-of-line data that they don’t exclusively own. After all, the memory cost must be known and fixed, and if there is shared data it’s not clear how it should be accounted.

Required Methods§

Source

fn indirect_memory_cost(&self, _: EnabledToken) -> usize

Memory cost of data stored out-of-line

The total memory cost is the cost of the layout of self plus this.

Implementations on Foreign Types§

Source§

impl HasMemoryCostStructural for IpAddr

Source§

impl HasMemoryCostStructural for i8

Source§

impl HasMemoryCostStructural for i16

Source§

impl HasMemoryCostStructural for i32

Source§

impl HasMemoryCostStructural for i64

Source§

impl HasMemoryCostStructural for isize

Source§

impl HasMemoryCostStructural for u8

Source§

impl HasMemoryCostStructural for u16

Source§

impl HasMemoryCostStructural for u32

Source§

impl HasMemoryCostStructural for u64

Source§

impl HasMemoryCostStructural for ()

Source§

impl HasMemoryCostStructural for usize

Source§

impl HasMemoryCostStructural for Ed25519Identity

Source§

impl HasMemoryCostStructural for ValidatableEd25519Signature

Source§

impl HasMemoryCostStructural for RsaIdentity

Source§

impl HasMemoryCostStructural for String

Source§

impl HasMemoryCostStructural for Ipv4Addr

Source§

impl HasMemoryCostStructural for Ipv6Addr

Source§

impl HasMemoryCostStructural for NonZero<i8>

Source§

impl HasMemoryCostStructural for NonZero<i16>

Source§

impl HasMemoryCostStructural for NonZero<i32>

Source§

impl HasMemoryCostStructural for NonZero<i64>

Source§

impl HasMemoryCostStructural for NonZero<isize>

Source§

impl HasMemoryCostStructural for NonZero<u8>

Source§

impl HasMemoryCostStructural for NonZero<u16>

Source§

impl HasMemoryCostStructural for NonZero<u32>

Source§

impl HasMemoryCostStructural for NonZero<u64>

Source§

impl HasMemoryCostStructural for NonZero<usize>

Source§

impl<A> HasMemoryCostStructural for (A,)

Source§

impl<A, B> HasMemoryCostStructural for (A, B)

Source§

impl<A, B, C> HasMemoryCostStructural for (A, B, C)

Source§

impl<A, B, C, D> HasMemoryCostStructural for (A, B, C, D)

Source§

impl<A, B, C, D, E> HasMemoryCostStructural for (A, B, C, D, E)

Source§

impl<A, B, C, D, E, F> HasMemoryCostStructural for (A, B, C, D, E, F)

Source§

impl<A, B, C, D, E, F, G> HasMemoryCostStructural for (A, B, C, D, E, F, G)

Source§

impl<A, B, C, D, E, F, G, H> HasMemoryCostStructural for (A, B, C, D, E, F, G, H)

Source§

impl<A, B, C, D, E, F, G, H, I> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I)

Source§

impl<A, B, C, D, E, F, G, H, I, J> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> HasMemoryCostStructural for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

impl<T> HasMemoryCostStructural for Option<T>

Source§

impl<T> HasMemoryCostStructural for Box<T>

Source§

impl<T> HasMemoryCostStructural for Vec<T>

Source§

impl<T, const N: usize> HasMemoryCostStructural for [T; N]

Source§

impl<const N: usize> HasMemoryCostStructural for CtByteArray<N>

Implementors§