Struct HedelCell

Source
pub struct HedelCell<T: Debug> { /* private fields */ }
Expand description

A safe custom RefCell-like cell, based on UnsafeCell, and relying on a BorrowFlag for runtime borrow checking.

Implementations§

Source§

impl<T: Debug> HedelCell<T>

Source

pub fn new(value: T) -> Self

The default constructor for HedelCell.

§Example
use hedel_rs::cell::HedelCell;

fn main() {
	let cell = HedelCell::<i32>::new(67);
	println!("{:?}", cell.get());
}
Source

pub fn try_get(&self) -> Result<RefHedel<'_, T>, HedelError>

Get a RefHedel pointing to the inner value in a HedelCell.

SAFETY: checks if a mutable borrow is active and panics. Also increments a shared reference counter.

§Example
use hedel_rs::cell::HedelCell;

fn main() {
	let cell = HedelCell::<i32>::new(56);
	let borrow = cell.get();
	let borrow_2 = cell.get();
	println!("{:?}", borrow); // prints 56
}
Source

pub fn get(&self) -> RefHedel<'_, T>

Guarantees to return RefHedel or panics!

Source

pub fn try_get_mut<'a>(&'a self) -> Result<RefMutHedel<'a, T>, HedelError>

Get a RefMutHedel mutably pointing to the inner value in a HedelCell.

SAFETY: panics when a mutable reference is alive or when there’s one or more shared references. Also sets the flag to BorrowFlag::Exclusive.

§Example
use hedel_rs::cell::HedelCell;

fn main() {
		
	let cell = HedelCell::<i32>::new(23);
	*cell.get_mut() = 36;
	let mut borrow = cell.get_mut();
	*borrow = 15;
	// this would panic
	// println!("{:?}", cell.get()); 
}
Source

pub fn get_mut(&self) -> RefMutHedel<'_, T>

Guarantees to return RefMutHedel or panics!

Source

pub fn into_inner(self) -> T

Consumes itself and returns the inner value

Trait Implementations§

Source§

impl<T: Debug + Debug> Debug for HedelCell<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for HedelCell<T>

§

impl<T> !RefUnwindSafe for HedelCell<T>

§

impl<T> Send for HedelCell<T>
where T: Send,

§

impl<T> !Sync for HedelCell<T>

§

impl<T> Unpin for HedelCell<T>
where T: Unpin,

§

impl<T> UnwindSafe for HedelCell<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.