Crates.io | dst |
lib.rs | dst |
version | 0.1.0 |
source | src |
created_at | 2021-02-07 18:07:01.198213 |
updated_at | 2021-02-07 18:07:01.198213 |
description | Data structures for DSTs |
homepage | https://github.com/Wolvereness/dst/ |
repository | https://github.com/Wolvereness/dst/ |
max_upload_size | |
id | 352023 |
size | 38,123 |
This crate is intended to provide data structures that use DSTs (dynamically sized types).
The goal of this crate is to provide data structures that can store DSTs in a contiguous allocation. Some applications may have a performance benefit for using a contiguous allocation as opposed to multiple pointers.
Currently, the only implementation is a Vec
where the DST-tails are
slices of the same length.
Add to dependencies:
[dependencies]
dst = "0.1.0"
Use in the code:
use dst::FixedVec;
fn main() {
let mut vec = FixedVec::<Option<&str>, usize>::new(4);
vec.push_default();
let item = vec.get(0).unwrap();
assert_eq!(item.value, None);
assert_eq!(item.tail, [0, 0, 0, 0]);
vec.push(Some("Name"), [1, 2, 3, 4].iter().copied());
let item = vec.get(1).unwrap();
assert_eq!(item.value, Some("Name"));
assert_eq!(item.tail, [1, 2, 3, 4]);
}
undefined_behavior
(disabled by default)
This flag enables the project to build on stable Rust, but by utilizing code with UB. Specifically, invalid intermediate references are used to obtain a pointer to initialize data and to obtain layout information. See:
unstable
(enabled by default)
This flag enables use of unstable Rust APIs. Specifically it allows UB to
be avoided, but also changes some of the crate's layout and size API to use
const
functions (presumably giving a runtime performance benefit). See
https://github.com/rust-lang/rust/issues/46571