static-box

Crates.iostatic-box
lib.rsstatic-box
version0.2.0
sourcesrc
created_at2021-05-06 20:13:10.896938
updated_at2021-07-07 20:31:27.637081
descriptionA stack-allocated box that stores trait objects.
homepage
repositoryhttps://github.com/alekseysidorov/static-box
max_upload_size
id393966
size30,640
Aleksey Sidorov (alekseysidorov)

documentation

https://docs.rs/static-box/

README

Continuous integration Crates.io API reference

Overview

This crate allows saving DST objects in the provided buffer. It allows users to create global dynamic objects on a no_std environment without a global allocator.

use static_box::Box;

struct Uart1Rx {
    // Implementation details...
}

impl SerialWrite for Uart1Rx {
    fn write(&mut self, _byte: u8) {
        // Implementation details
    }
}
let rx = Uart1Rx { /* ... */ };

let mut buf = [0; 32];
let mut writer = Box::<dyn SerialWrite>::new(&mut buf, rx);
writer.write_str("Hello world!");

This implementation is inspired by the thin_box example in the rustc tests repository.

Minimum Supported rustc Version

This crate uses following unstable features:

In other words, the crate's supported nightly rustc version is 1.53.0, but there is no guarantee that this code will work fine on the newest versions.

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.

Commit count: 36

cargo fmt