subrc

Crates.iosubrc
lib.rssubrc
version0.2.0
sourcesrc
created_at2023-07-06 13:42:52.713413
updated_at2023-07-06 14:22:13.003995
descriptionA tiny crate that exposes a `Rc` like struct, which can be used to create a reference counted pointer to a subregion of a `Rc`.
homepage
repositoryhttps://github.com/hillin/subrc
max_upload_size
id909908
size6,844
(hillin)

documentation

https://docs.rs/subrc

README

Subrc

crates.io docs.rs

A tiny crate that exposes a Rc like struct, which can be used to create a reference counted pointer to a subregion (member, or member of member etc.) of a Rc.

Example

struct Foo {
    value: i32,
}

let rc = Rc::new(Foo { value: 42 });
let subrc = Subrc::new(rc.clone(), |foo| &foo.value);
// or 
let subrc = subrc!(rc.value);

// subrc derefs to 42
assert_eq!(*subrc, 42);
// subrc points to rc.value
assert!(std::ptr::eq(&*subrc, &rc.value));
Commit count: 8

cargo fmt