#thin #dst #dynamically-sized #thin-pointer

deprecated no-std thin-dst

Thin pointers to inline-slice dynamically sized types

6 releases (2 stable)

1.1.0 Mar 18, 2020
1.0.0 Nov 19, 2019
1.0.0-beta.4 Nov 14, 2019
1.0.0-beta.1 Nov 10, 2019

#21 in #dynamically-sized

Download history 512/week @ 2023-12-06 603/week @ 2023-12-13 624/week @ 2023-12-20 391/week @ 2023-12-27 460/week @ 2024-01-03 572/week @ 2024-01-10 633/week @ 2024-01-17 472/week @ 2024-01-24 477/week @ 2024-01-31 523/week @ 2024-02-07 633/week @ 2024-02-14 566/week @ 2024-02-21 671/week @ 2024-02-28 557/week @ 2024-03-06 509/week @ 2024-03-13 534/week @ 2024-03-20

2,352 downloads per month
Used in 4 crates (via dsrs)

MIT/Apache

30KB
541 lines

thin-dst

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.

Alternative

slice-dst is a successor to this crate, which, along with the other pointer-utils crates, offers a more composable API.

This crate will continue to be reactively maintained, but any future development will focus on pointer-utils/slice-dst instead.

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.

License

Licensed under either of

at your option.

If you are a highly paid worker at any company that prioritises profit over people, you can still use this crate. I simply wish you will unionise and push back against the obsession for growth, control, and power that is rampant in your workplace. Please take a stand against the horrible working conditions they inflict on your lesser paid colleagues, and more generally their disrespect for the very human rights they claim to fight for.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps