Skip to main content

TRefLock

Struct TRefLock 

Source
pub struct TRefLock<T: ?Sized> { /* private fields */ }
Expand description

J-C cfg-gated interior-mutable lock. Exposes RefCell-shaped .borrow() / .borrow_mut() whose returned guards Deref<Target = T>. Under the default feature set this is a thin newtype around RefCell<T> (zero overhead vs. the pre-J-C RefCell field); under feature = "send" it wraps RwLock<T> and the guards become RwLockReadGuard / RwLockWriteGuard.

Lock failure handling: the send build unwrap()s the lock result. The SendVm’s outer RwLock<()> serializes mutator access so a poisoned lock is a real bug (a panic in a guard’s user) and the propagating panic is the same UX as RefCell::borrow_mut on a re-entrant borrow.

Implementations§

Source§

impl<T> TRefLock<T>

Source

pub const fn new(v: T) -> Self

Construct a new lock around v.

Source

pub fn borrow(&self) -> Ref<'_, T>

Borrow the lock immutably. The returned guard derefs to &T; callers use it identically to RefCell::borrow.

Source

pub fn borrow_mut(&self) -> RefMut<'_, T>

Borrow the lock mutably. The returned guard derefs to &mut T; callers use it identically to RefCell::borrow_mut.

Trait Implementations§

Source§

impl<T: Debug + ?Sized> Debug for TRefLock<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 TRefLock<T>

§

impl<T> !RefUnwindSafe for TRefLock<T>

§

impl<T> !Sync for TRefLock<T>

§

impl<T> Send for TRefLock<T>
where T: Send + ?Sized,

§

impl<T> Unpin for TRefLock<T>
where T: Unpin + ?Sized,

§

impl<T> UnsafeUnpin for TRefLock<T>
where T: UnsafeUnpin + ?Sized,

§

impl<T> UnwindSafe for TRefLock<T>
where T: UnwindSafe + ?Sized,

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.