pub struct PacCell<P, C>(/* private fields */);
Expand description
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.
§Examples
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.
Implementations§
Source§impl<'p, P: 'p, C> PacCell<P, C>
impl<'p, P: 'p, C> PacCell<P, C>
Sourcepub fn new<F>(parent: P, child_constructor: F) -> Self
pub fn new<F>(parent: P, child_constructor: F) -> Self
Creates Pac by moving the parent into a Box and then calling the child constructor.
Sourcepub fn try_new<F, E>(parent: P, child_constructor: F) -> Result<Self, E>
pub fn try_new<F, E>(parent: P, child_constructor: F) -> Result<Self, E>
Creates Pac by moving the parent into a Box and then calling the child constructor.
Auto Trait Implementations§
impl<P, C> Freeze for PacCell<P, C>
impl<P, C> !RefUnwindSafe for PacCell<P, C>
impl<P, C> Send for PacCell<P, C>
impl<P, C> !Sync for PacCell<P, C>
impl<P, C> Unpin for PacCell<P, C>
impl<P, C> UnwindSafe for PacCell<P, C>where
P: UnwindSafe,
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more