Compact

Trait Compact 

Source
pub trait Compact: Sized + Clone {
    // Required methods
    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;

    // Provided methods
    fn total_size_bytes(&self) -> usize { ... }
    unsafe fn behind(ptr: *mut Self) -> *mut u8 { ... }
    unsafe fn compact_behind(source: *mut Self, dest: *mut Self) { ... }
}
Expand description

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§

Source

fn is_still_compact(&self) -> bool

Is the object’s dynamic part stored compactly?

Source

fn dynamic_size_bytes(&self) -> usize

Size of the dynamic part in bytes

Source

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.

Source

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.

Provided Methods§

Source

fn total_size_bytes(&self) -> usize

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

Source

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)

Source

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

Like compact with new_dynamic_part set to dest.behind()

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Compact for CompactString

Source§

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

Source§

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

Source§

impl<T: Clone + Compact> Compact for CompactOption<T>

Source§

impl<T: Copy> Compact for T

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

Source§

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

Source§

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