Crates.io | subrc |
lib.rs | subrc |
version | 0.2.0 |
source | src |
created_at | 2023-07-06 13:42:52.713413 |
updated_at | 2023-07-06 14:22:13.003995 |
description | 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`. |
homepage | |
repository | https://github.com/hillin/subrc |
max_upload_size | |
id | 909908 |
size | 6,844 |
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
.
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));