[][src]Trait compact::Compact

pub trait Compact: Sized + Clone {
    fn is_still_compact(&self) -> bool;
fn dynamic_size_bytes(&self) -> usize;
unsafe fn compact(
        source: *mut Self,
        dest: *mut Self,
        new_dynamic_part: *mut u8
    );
unsafe fn decompact(source: *const Self) -> Self; fn total_size_bytes(&self) -> usize { ... }
unsafe fn behind(ptr: *mut Self) -> *mut u8 { ... }
unsafe fn compact_behind(source: *mut Self, dest: *mut Self) { ... } }

A trait for objects with a statically-sized part and a potential dynamically-sized part that can be stored both compactly in consecutive memory or freely on the heap

Required methods

fn is_still_compact(&self) -> bool

Is the object's dynamic part stored compactly?

fn dynamic_size_bytes(&self) -> usize

Size of the dynamic part in bytes

unsafe fn compact(source: *mut Self, dest: *mut Self, new_dynamic_part: *mut u8)

Copy the static part of source to dest and compactly store the dynamic part of source as the new dynamic part of dest at new_dynamic_part. This semantically moves source into dest.

unsafe fn decompact(source: *const Self) -> Self

Creates a clone of self with the dynamic part guaranteed to be stored freely.

Note: if the dynamic part was already stored freely, the calling environment has to make sure that old self will not be dropped, as this might lead to a double free!

This is mostly used internally to correctly implement Compact datastructures that contain Compact elements.

Loading content...

Provided methods

fn total_size_bytes(&self) -> usize

Total size of the object (static part + dynamic part)

unsafe fn behind(ptr: *mut Self) -> *mut u8

Get a pointer to behind the static part of self (commonly used place for the dynamic part)

unsafe fn compact_behind(source: *mut Self, dest: *mut Self)

Like compact with new_dynamic_part set to dest.behind()

Loading content...

Implementors

impl Compact for CompactString[src]

impl<K: Copy + Eq + Hash, V: Compact, A: Allocator> Compact for OpenAddressingMap<K, V, A>[src]

impl<K: Copy, V: Compact + Clone, A: Allocator> Compact for CompactDict<K, V, A>[src]

impl<T: Compact + Clone, A: Allocator> Compact for CompactVec<T, A>[src]

impl<T: Clone + Compact> Compact for CompactOption<T>[src]

impl<T: Copy> Compact for T[src]

Trivial implementation for fixed-sized, Copy types (no dynamic part)

impl<T: Copy, A: Allocator> Compact for CompactVec<T, A>[src]

Loading content...