pub struct GlobalRef<T> { /* private fields */ }
Expand description
A cell to store immutable reference.
§Safety
Because the implementation internally converts raw pointers to usize and shares them between threads, fetching references is essentially unsafe. Please verify its safety before using it.
Implementations§
Source§impl<T> GlobalRef<T>
impl<T> GlobalRef<T>
Sourcepub unsafe fn set(&self, item: &T)
pub unsafe fn set(&self, item: &T)
Set a reference so that other functions can obtain it through GlobalRef.
It is recommended to use with()
instead.
Be sure to call clear()
after it is used.
Sourcepub fn with<F, R>(&self, item: &T, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn with<F, R>(&self, item: &T, f: F) -> Rwhere
F: FnOnce() -> R,
Set a reference and clear the reference after calling the given closure.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for GlobalRef<T>
impl<T> RefUnwindSafe for GlobalRef<T>where
T: RefUnwindSafe,
impl<T> Send for GlobalRef<T>where
T: Send,
impl<T> Sync for GlobalRef<T>where
T: Sync,
impl<T> Unpin for GlobalRef<T>where
T: Unpin,
impl<T> UnwindSafe for GlobalRef<T>where
T: 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