Rust library providing `Zc` for self-referential zero-copy structures
Last updated Sep 30, 2024
41
Stars
1
Forks
0
Issues
0
Stars/day
Attention Score
6
Topics
Language breakdown
Rust 100.0%
โธ Files
click to expand
README
rust-zc
Rust library providing Zc for self-referential zero-copy structures. Documentation hosted on docs.rs.
zc = "0.4"
Usage
use zc::Dependant;
#[derive(PartialEq, Debug, Dependant)] pub struct StructWithBytes<'a>(&'a [u8]);
impl<'a> From<&'a [u8]> for StructWithBytes<'a> { fn from(bytes: &'a [u8]) -> Self { Self(&bytes[1..]) } }
fn main() { let owner = vec![1, 2, 3]; let data = zc::from!(owner, StructWithBytes, [u8]);
assert_eq!( data.get::<StructWithBytes>(), &StructWithBytes(&[2, 3]) ) }
Testing
Run standard tests:
cargo test
Run miri tests:
cargo miri test --test test_zc๐ More in this category