Docs.rs
  • dyn-stack-0.13.0
    • dyn-stack 0.13.0
    • Permalink
    • Docs.rs crate page
    • MIT
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • sarah-quinones
    • Dependencies
      • bytemuck ^1 normal
      • criterion ^0.4 dev
    • Versions
    • 80% of the crate is documented
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate dyn_stack

dyn_stack0.13.0

  • All Items

Sections

  • Examples:

Crate Items

  • Re-exports
  • Modules
  • Structs
  • Traits
  • Type Aliases

Crates

  • dyn_stack

Crate dyn_stack

Source
Expand description

Stack that allows users to allocate dynamically sized arrays.

The stack wraps a buffer of bytes that it uses as a workspace. Allocating an array takes a chunk of memory from the stack, which can be reused once the array is dropped.

§Examples:

use core::mem::MaybeUninit;
use dyn_stack::{MemStack, StackReq};

// We allocate enough storage for 3 `i32` and 4 `u8`.
let mut buf = [MaybeUninit::uninit();
    StackReq::new::<i32>(3)
        .and(StackReq::new::<u8>(4))
        .unaligned_bytes_required()];
let stack = MemStack::new(&mut buf);

{
    // We can have nested allocations.
    // 3×`i32`
    let (array_i32, substack) = stack.make_with::<i32>(3, |i| i as i32);
    // and 4×`u8`
    let (mut array_u8, _) = substack.make_with::<u8>(4, |_| 0);

    // We can read from the arrays,
    assert_eq!(array_i32[0], 0);
    assert_eq!(array_i32[1], 1);
    assert_eq!(array_i32[2], 2);

    // and write to them.
    array_u8[0] = 1;

    assert_eq!(array_u8[0], 1);
    assert_eq!(array_u8[1], 0);
    assert_eq!(array_u8[2], 0);
    assert_eq!(array_u8[3], 0);
}

// We can also have disjoint allocations.
{
    // 3×`i32`
    let (mut array_i32, _) = stack.make_with::<i32>(3, |i| i as i32);
    assert_eq!(array_i32[0], 0);
    assert_eq!(array_i32[1], 1);
    assert_eq!(array_i32[2], 2);
}

{
    // or 4×`u8`
    let (mut array_u8, _) = stack.make_with::<i32>(4, |i| i as i32 + 3);
    assert_eq!(array_u8[0], 3);
    assert_eq!(array_u8[1], 4);
    assert_eq!(array_u8[2], 5);
    assert_eq!(array_u8[3], 6);
}

Re-exports§

pub use mem::MemBuffer;alloc
pub use mem::PodBuffer;alloc

Modules§

alloc
mem

Structs§

Bump
DynArray
Owns an unsized array of data, allocated from some stack.
MemStack
Stack wrapper around a buffer of uninitialized bytes.
PodStack
Stack wrapper around a buffer of bytes.
StackReq
Stack allocation requirements.
UnpodStack
Owns an unsized array of data, allocated from some stack.

Traits§

Error
Error is a trait representing the basic expectations for error values, i.e., values of type E in Result<T, E>.

Type Aliases§

DynStack

Results

Settings
Help
    type alias
    dyn_stack::DynStack
    extern crate
    dyn_stack
    Stack that allows users to allocate dynamically sized …
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.