arc-ext 0.1.0

Extensions for Arc<T> such as field projection
Documentation
  • Coverage
  • 0%
    0 out of 6 items documented0 out of 3 items with examples
  • Size
  • Source code size: 40.53 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.78 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • bbqsrc/arc-ext
    3 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bbqsrc

arc-ext

Extensions for Arc<T> such as field projection.

Usage

The ArcExt trait implementation extends Arc<T> with .project and .project_option methods.

The projection enforces lifetimes, so that no reference to it can outlive the projection (and therefore is not unsound).

See the following example:

use arc_ext::ArcExt;

#[derive(Debug, PartialEq, Eq)]
struct Top {
    nested: Nested,
    string: String,
}

#[derive(Debug, PartialEq, Eq)]
struct Nested {
    a: u32,
    b: Box<[u8]>,
    c: Option<Arc<Top>>,
}

fn test() {
    let top = Arc::new(Top {
        nested: Nested {
            a: 32,
            b: vec![1, 2, 3, 4].into_boxed_slice(),
            c: Some(Arc::new(Top {
                nested: Nested {
                    a: 12,
                    b: vec![99].into_boxed_slice(),
                    c: None,
                },
                string: "nested".to_string(),
            })),
        },
        string: "owned str".to_string(),
    });

    let project = top.clone().project(|x| &x.nested.b);
    assert_eq!(&[1, 2, 3, 4], &**project);
    drop(project);

    let project = top.clone().project_option(|x| x.nested.c.as_ref());
    let opt = project.as_option().unwrap();
    assert_eq!(top.nested.c.as_ref().unwrap(), opt);
}

License

This project is licensed under either of

at your option.