| Crates.io | refcon |
| lib.rs | refcon |
| version | 0.2.0 |
| created_at | 2024-06-07 07:47:10.044782+00 |
| updated_at | 2024-06-07 10:01:24.156916+00 |
| description | A reference-behaving type indifferently wrapping reference or immediate values |
| homepage | |
| repository | https://github.com/delehef/refcon |
| max_upload_size | |
| id | 1264482 |
| size | 33,610 |
This crate provides the Refcon enum, which is used to wrap either a
concrete instance of a type T, or a reference to one.
By implementing AsRef<T>, Refcon lets either variant seamlessly
behave as a reference to T.
const ZERO = ABigStruct::costly_initializer();
let v: Vec<ABigStruct> = (0..10_000)
.map(|i|
if i < 1_000 {
Refcon::from(&ZERO)
} else {
Refcon::from(ABigStruct::new(i))
})
.collect();
// [...]
for x in {
x.do_something();
}
T is smaller than two machine words – you should just copy everything
in this case anyways;