Trait succinct::SpaceUsage
[−]
[src]
pub trait SpaceUsage: Sized { fn is_stack_only() -> bool; fn total_bytes(&self) -> usize { ... } fn stack_bytes() -> usize { ... } fn heap_bytes(&self) -> usize { ... } }
Types that know how to compute their space usage.
We calculate the space usage is split into two portions, the heap
portion (returned by heap_bytes
and the stack portion (returned by
stack_bytes
). The stack portion is the statically-known size for
every object of its type as allocated on the stack; the dynamic
portion is the additional heap allocation that may depend on
run-time factors.
Examples:
Primitive types like
u32
andusize
are stack-only.A tuple or struct type is stack-only when all its components are. Its heap portion is the sum of their heap portions, but its stack portion may exceed the sum of their stack portions because of alignment and padding.
The size of a vector includes a stack portion, the vector struct itself, and a heap portion, the array holding its elements. The heap portion of a vector includes the stack portions of its elements. (Should they be called something else for this reason? I considered static/dynamic, but
Box
shows why that doesn’t express exactly the right property.)
Required Methods
fn is_stack_only() -> bool
Is the size of this type known statically?
If this method returns true then heap_bytes
should always
return 0.
Provided Methods
fn total_bytes(&self) -> usize
Computes the size of the receiver in bytes.
This includes not just the immediate stack object, but any heap memory that it owns.
The default implementation returns
Self::stack_bytes() + self.heap_bytes()
.
fn stack_bytes() -> usize
Calculates the stack portion of the size of this type.
This is the size of the immediate storage that all objects of this type occupy; it excludes storage that objects of the type might allocate dynamically.
The default implementation returns std::mem::size_of::<Self>()
.
fn heap_bytes(&self) -> usize
Calculates the heap portion of the size of an object.
This is the memory used by (or, rather, owned by) the object, not
including any portion of its size that is
included in stack_bytes
. This is typically for containers
that heap allocate varying amounts of memory.
The default implementation returns 0
.
Implementors
impl<Block: BlockType> SpaceUsage for BitVec<Block>
impl<'a, Base: 'a + Bits> SpaceUsage for BitSlice<'a, Base>
impl<'a, Base: 'a + BitsMut> SpaceUsage for BitSliceMut<'a, Base>
impl<A: BlockType> SpaceUsage for IntVec<A>
impl<'a, Store: ?Sized + Bits + 'a> SpaceUsage for JacobsonRank<'a, Store>
impl<'a, Rank: BitRankSupport + 'a> SpaceUsage for BinSearchSelect<'a, Rank>
impl SpaceUsage for ()
impl SpaceUsage for u8
impl SpaceUsage for u16
impl SpaceUsage for u32
impl SpaceUsage for u64
impl SpaceUsage for usize
impl SpaceUsage for i8
impl SpaceUsage for i16
impl SpaceUsage for i32
impl SpaceUsage for i64
impl SpaceUsage for isize
impl SpaceUsage for f32
impl SpaceUsage for f64
impl<A: SpaceUsage> SpaceUsage for (A,)
impl<A: SpaceUsage, B: SpaceUsage> SpaceUsage for (A, B)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage> SpaceUsage for (A, B, C)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage> SpaceUsage for (A, B, C, D)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage> SpaceUsage for (A, B, C, D, E)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage, F: SpaceUsage> SpaceUsage for (A, B, C, D, E, F)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage, F: SpaceUsage, G: SpaceUsage> SpaceUsage for (A, B, C, D, E, F, G)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage, F: SpaceUsage, G: SpaceUsage, H: SpaceUsage> SpaceUsage for (A, B, C, D, E, F, G, H)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage, F: SpaceUsage, G: SpaceUsage, H: SpaceUsage, I: SpaceUsage> SpaceUsage for (A, B, C, D, E, F, G, H, I)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage, F: SpaceUsage, G: SpaceUsage, H: SpaceUsage, I: SpaceUsage, J: SpaceUsage> SpaceUsage for (A, B, C, D, E, F, G, H, I, J)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage, F: SpaceUsage, G: SpaceUsage, H: SpaceUsage, I: SpaceUsage, J: SpaceUsage, K: SpaceUsage> SpaceUsage for (A, B, C, D, E, F, G, H, I, J, K)
impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage, F: SpaceUsage, G: SpaceUsage, H: SpaceUsage, I: SpaceUsage, J: SpaceUsage, K: SpaceUsage, L: SpaceUsage> SpaceUsage for (A, B, C, D, E, F, G, H, I, J, K, L)
impl<A: SpaceUsage + Debug> SpaceUsage for Vec<A>
impl<A: SpaceUsage> SpaceUsage for Box<A>