#zero-copy #parser

no-std zc

Self-referential zero-copy structure

3 releases (breaking)

0.4.0 Feb 18, 2021
0.3.0 Jan 20, 2021
0.2.0 Dec 23, 2020
0.1.2 Dec 8, 2020

#385 in Memory management

Download history 40/week @ 2023-12-31 14/week @ 2024-02-18 18/week @ 2024-02-25 6/week @ 2024-03-03 12/week @ 2024-03-10 4/week @ 2024-03-17 35/week @ 2024-03-31

52 downloads per month
Used in dangerous

MIT license

26KB
410 lines

Build Status Coverage Status Crate Docs

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

Dependencies

~210KB