Crates.io | pac_cell |
lib.rs | pac_cell |
version | 0.1.1 |
source | src |
created_at | 2024-04-14 17:31:36.337826 |
updated_at | 2024-04-14 17:36:14.523896 |
description | Parent and child cell |
homepage | https://github.com/aljazerzen/pac_cell |
repository | |
max_upload_size | |
id | 1208411 |
size | 12,833 |
A cell of a parent and a child, which is created by mutably borrowing the parent. While the parent is in the cell, it cannot be accessed in any way. Provides mutable access to the child.
This is useful in a rare case when you need to store and move both parent and their child together.
Basic usage:
struct Hello {
world: i64,
}
let hello = Hello { world: 10 };
let mut pac = pac_cell::PacCell::new(hello, |h| &mut h.world);
let initial = pac.with_mut(|world| {
let i = **world;
**world = 12;
i
});
assert_eq!(initial, 10);
let hello_again = pac.unwrap();
assert_eq!(hello_again.world, 12);
For a real-world-like example, see the crate tests.
This crate has unsound functions (such as PacCell::new
), which might might lead
to undefined behavior when used "incorrectly".
See https://users.rust-lang.org/t/soundness-of-pac-cell-library/108598/4