4 releases (breaking)

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

#22 in #self-referential

Download history 14/week @ 2024-03-31 8/week @ 2024-04-07 36/week @ 2024-04-14 26/week @ 2024-04-21 1/week @ 2024-04-28 4/week @ 2024-05-12 2/week @ 2024-05-19 4/week @ 2024-05-26 25/week @ 2024-06-02 2/week @ 2024-06-09 13/week @ 2024-06-16 9/week @ 2024-06-23 6/week @ 2024-06-30 30/week @ 2024-07-07

59 downloads per month
Used in zc

MIT license

8KB
142 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

~1.5MB
~35K SLoC