Crates.io | zc |
lib.rs | zc |
version | 0.4.0 |
source | src |
created_at | 2020-12-08 07:15:52.099806 |
updated_at | 2021-02-18 05:00:18.224418 |
description | Self-referential zero-copy structure |
homepage | https://github.com/avitex/rust-zc |
repository | https://github.com/avitex/rust-zc |
max_upload_size | |
id | 320720 |
size | 44,330 |
Rust library providing Zc
for self-referential zero-copy structures.
Documentation hosted on docs.rs.
zc = "0.4"
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])
)
}
Run standard tests:
cargo test
Run miri tests:
cargo miri test --test test_zc