#stack #dst

stack_dst

A wrapper that allows storage of unsized values of up to a fixed size inline (without boxing)

17 releases

Uses old Rust 2015

0.7.2 Jul 20, 2022
0.7.1 Feb 26, 2022
0.6.1 Mar 3, 2021
0.6.0 Jan 25, 2020
0.0.1 Jun 2, 2015

#192 in Rust patterns

Download history 84/week @ 2022-11-26 86/week @ 2022-12-03 121/week @ 2022-12-10 43/week @ 2022-12-17 76/week @ 2022-12-24 32/week @ 2022-12-31 26/week @ 2023-01-07 77/week @ 2023-01-14 118/week @ 2023-01-21 51/week @ 2023-01-28 169/week @ 2023-02-04 58/week @ 2023-02-11 143/week @ 2023-02-18 137/week @ 2023-02-25 81/week @ 2023-03-04 100/week @ 2023-03-11

471 downloads per month
Used in 7 crates (via stylish-core)

MIT/Apache

40KB
786 lines

stack_dst

Inline (aka stack-allocated) dynamically-sized types

Overview

This crate provides ways of storing DSTs inline (not needing a heap allocation)

Basic usage

This crate covers two primary usecases

  • Value allows storing (and returning) a single DST within a fixed-size allocation.
  • Stack and Fifo allow heterogeneous collections without needing to box each object.

Example

One of the most obvious uses is to allow returning capturing closures without having to box them. In the example below, the closure takes ownership of value, and is then returned using a Value

use stack_dst::Value;

fn make_closure(value: u64) -> Value<dyn Fn()->String> {
    Value::new(move || format!("Hello there! value={}", value)).ok().expect("Closure doesn't fit")
}
let closure = make_closure(12);
assert_eq!( closure(), "Hello there! value=12" );

Status

  • Works for most test cases
  • Not rigourously tested across platforms

Minimum rust version

  • Uses MaybeUninit, so requires at least 1.36

License

Licensed under either of

at your option.

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

Features

  • alloc
  • const_generics
  • std
  • unsize