Crate thin_dst

Source
Expand description

Boxed custom DSTs that store a slice and the length of said slice inline. Uses the standard library collection types for full interoperability, and also provides thin owned pointers for space-conscious use.

§Examples

The simplest example is just a boxed slice:

let boxed_slice = ThinBox::new((), vec![0, 1, 2, 3, 4, 5]);
assert_eq!(&*boxed_slice, &[0, 1, 2, 3, 4, 5][..]);
let boxed_slice: Box<ThinData<(), u32>> = boxed_slice.into();

All of the thin collection types are constructed with a “head” and a “tail”. The head is any Sized type that you would like to associate with the slice. The “tail” is the owned slice of data that you would like to store.

This creates a collection of ThinData, which acts like { head, tail }, and also handles the unsafe required for both custom slice DSTs and thin DST pointers. The most idiomatic usage is to encapsulate the use of thin-dst with a transparent newtype:

#[repr(transparent)]
struct NodeData(ThinData<NodeHead, Node>);
struct Node(ThinArc<NodeHead, Node>);

And then use NodeData by transmuting and/or ref-casting as needed.

Structs§

ThinArc
A thin version of Arc.
ThinBox
A thin version of Box.
ThinData
A custom slice-holding dynamically sized type. Stores slice length inline to be thin-pointer compatible.
ThinPtr
ThinRc
A thin version of Rc.
ThinRef
ThinRefMut

Type Aliases§

ErasedPtr
An erased pointer with size and stride of one byte.