Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timvermeulen/const-buffer
A fixed-capacity memory buffer allocated on the stack using const generics.
https://github.com/timvermeulen/const-buffer
array const-generics data-structures no-std rust
Last synced: 16 days ago
JSON representation
A fixed-capacity memory buffer allocated on the stack using const generics.
- Host: GitHub
- URL: https://github.com/timvermeulen/const-buffer
- Owner: timvermeulen
- License: apache-2.0
- Created: 2020-02-03T23:09:49.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-06T21:26:25.000Z (about 4 years ago)
- Last Synced: 2024-04-25T09:02:30.865Z (7 months ago)
- Topics: array, const-generics, data-structures, no-std, rust
- Language: Rust
- Homepage: https://crates.io/crates/const-buffer
- Size: 17.6 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# const-buffer
[![crates.io](https://img.shields.io/crates/v/const-buffer)](https://crates.io/crates/const-buffer)
[![docs.rs](https://docs.rs/const-buffer/badge.svg)](https://docs.rs/const-buffer)
![rustc version](https://img.shields.io/badge/rustc-nightly-inactive)A fixed-capacity memory buffer allocated on the stack using const generics.
This is a low-level utility, useful for implementing higher-level data structures such as fixed-capacity vectors and ring buffers. Since `ConstBuffer`'s main purpose is to build safe abstractions on top of, almost its entire API surface is `unsafe`.
`ConstBuffer` does not keep track of which elements are in an initialized state. Furthermore, in order to ensure optimal performance, **no bounds checks are performed** unless debug assertions are enabled. Any misuse of this crate leads to undefined behavior.
## Example usage
```rust
use const_buffer::ConstBuffer;fn main() {
let mut buffer = ConstBuffer::::new();unsafe {
buffer.copy_from_slice(2, &[10, 20, 30]);
// [_, _, 10, 20, 30, _, _, _, _, _]
buffer.write(5, 40);
// [_, _, 10, 20, 30, 40, _, _, _, _]
assert_eq!(buffer.get(3), &20);
assert_eq!(buffer.get(2..6), &[10, 20, 30, 40]);buffer.copy_within(2..6, 0);
// [10, 20, 30, 40, 30, 40, _, _, _, _]
buffer.get_mut(1..4).reverse();
// [10, 40, 30, 20, 30, 40, _, _, _, _]
assert_eq!(buffer.get(..6), &[10, 40, 30, 20, 30, 40]);buffer.swap(3, 8);
// [10, 40, 30, _, 30, 40, _, _, 20, _]
assert_eq!(buffer.read(8), 20);
}
}
```## License
Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or [MIT License](LICENSE-MIT) at your option. Any source contributions will be dual-licensed in the same way.