#rc #pointers #memory

subrc

A tiny crate that exposes a Rc like struct, which can be used to create a reference counted pointer to a subregion of a Rc

2 unstable releases

0.2.0 Jul 6, 2023
0.1.0 Jul 6, 2023

#799 in Memory management

MIT license

6KB
85 lines

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));

No runtime deps