Crates.io | out-reference |
lib.rs | out-reference |
version | 0.2.0 |
source | src |
created_at | 2019-01-09 20:01:06.004777 |
updated_at | 2021-01-20 15:26:44.723658 |
description | out references |
homepage | |
repository | |
max_upload_size | |
id | 107661 |
size | 6,753 |
This crate brings out references to Rust, this crate has no_std
support
Out reference never read values behind the reference
use out_reference::*;
let mut x = 0;
let mut out_x: Out<'_, u32> = x.out();
out_x.set(10);
assert_eq!(x, 10);
Note that setting a value does not drop the old value, as that would require at least 1 read of the value behind the pointer
So, the code below leaks the vector
use out_reference::*;
let mut x = vec![0, 1, 2];
let mut out_x: Out<'_, Vec<u32>> = x.out();
out_x.set(vec![]);
assert_eq!(x, vec![]);