[][src]Trait succinct::SpaceUsage

pub trait SpaceUsage: Sized {
    fn is_stack_only() -> bool;
fn heap_bytes(&self) -> usize; fn total_bytes(&self) -> usize { ... }
fn stack_bytes() -> usize { ... } }

Computes the space usage of an object.

We calculate the space usage as 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 and usize 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.

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.

Loading content...

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

Loading content...

Implementations on Foreign Types

impl SpaceUsage for ()[src]

impl SpaceUsage for u8[src]

impl SpaceUsage for u16[src]

impl SpaceUsage for u32[src]

impl SpaceUsage for u64[src]

impl SpaceUsage for usize[src]

impl SpaceUsage for i8[src]

impl SpaceUsage for i16[src]

impl SpaceUsage for i32[src]

impl SpaceUsage for i64[src]

impl SpaceUsage for isize[src]

impl SpaceUsage for f32[src]

impl SpaceUsage for f64[src]

impl<'a, T> SpaceUsage for &'a T[src]

impl<'a, T> SpaceUsage for &'a [T][src]

impl<A: SpaceUsage> SpaceUsage for (A,)[src]

impl<A: SpaceUsage, B: SpaceUsage> SpaceUsage for (A, B)[src]

impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage> SpaceUsage for (A, B, C)[src]

impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage> SpaceUsage for (A, B, C, D)[src]

impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage> SpaceUsage for (A, B, C, D, E)[src]

impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage, F: SpaceUsage> SpaceUsage for (A, B, C, D, E, F)[src]

impl<A: SpaceUsage, B: SpaceUsage, C: SpaceUsage, D: SpaceUsage, E: SpaceUsage, F: SpaceUsage, G: SpaceUsage> SpaceUsage for (A, B, C, D, E, F, G)[src]

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)[src]

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)[src]

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)[src]

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)[src]

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)[src]

impl<A: SpaceUsage + Debug> SpaceUsage for Vec<A>[src]

impl<A: SpaceUsage> SpaceUsage for Box<A>[src]

Loading content...

Implementors

impl<'a, Base: 'a + BitVec + ?Sized> SpaceUsage for BitSlice<'a, Base>[src]

impl<'a, Base: 'a + BitVecMut + ?Sized> SpaceUsage for BitSliceMut<'a, Base>[src]

impl<A: BlockType> SpaceUsage for IntVector<A>[src]

impl<Block: BlockType> SpaceUsage for BitVector<Block>[src]

impl<Rank: SpaceUsage> SpaceUsage for BinSearchSelect<Rank>[src]

impl<Store: SpaceUsage> SpaceUsage for JacobsonRank<Store>[src]

impl<Store: SpaceUsage> SpaceUsage for Rank9<Store>[src]

Loading content...