Skip to main content

Module ref_counted_pointer

Module ref_counted_pointer 

Source
Expand description

Reference-counted pointers with shared ownership, unwrapping, and take-cell capabilities.

In addition to cloneable shared pointers, this module provides a TakeCellOf abstraction: a cloneable cell that holds a value which can be taken exactly once. This pairs the appropriate interior mutability primitive with each pointer type (RefCell for Rc, Mutex for Arc), enabling move-out-of-closure patterns while preserving thread safety when needed.

§Examples

use fp_library::{
	brands::*,
	functions::*,
};

let ptr = ref_counted_pointer_new::<RcBrand, _>(42);
let clone = ptr.clone();
assert_eq!(*clone, 42);

let cell = take_cell_new::<RcBrand, _>(99);
let cell_clone = cell.clone();
assert_eq!(take_cell_take::<RcBrand, _>(&cell), Some(99));
assert_eq!(take_cell_take::<RcBrand, _>(&cell_clone), None);

Traits§

RefCountedPointer
Extension trait for reference-counted pointers with shared ownership.

Functions§

cloneable_new
Wraps a sized value in a cloneable pointer.
take_cell_new
Creates a new take-cell containing the given value.
take_cell_take
Takes the value out of a take-cell, leaving None behind.
try_unwrap
Attempts to unwrap the inner value if this is the sole reference.