2 releases

0.1.1 Apr 14, 2024
0.1.0 Apr 14, 2024

#1034 in Data structures

Download history 126/week @ 2024-07-24 142/week @ 2024-07-31 42/week @ 2024-08-07 33/week @ 2024-08-14 21/week @ 2024-08-21 169/week @ 2024-08-28 142/week @ 2024-09-04 76/week @ 2024-09-11 74/week @ 2024-09-18 70/week @ 2024-09-25 192/week @ 2024-10-02 213/week @ 2024-10-09 165/week @ 2024-10-16 204/week @ 2024-10-23 153/week @ 2024-10-30 142/week @ 2024-11-06

675 downloads per month
Used in 2 crates (via connector_arrow)

MIT license

6KB

Parent and Child cell

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.

Example

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.

Soundness

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

No runtime deps