pub struct Ref<T: ?Sized> { /* private fields */ }Expand description
A sendable shared reference backed by a Lien.
A Ref<T> represents a borrow of T from a Scope. Like a static
borrow with &T, this forces the Scope to outlive any Refs made from
it. But like an Arc, Ref<T> carries no lifetime (it’s atomically
reference-counted at runtime), is thread-safe, and can be freely cloned.
Ref<T> requires T: Sync to be Send, like &T:
ⓘ
use std::cell::Cell;
fn assert_send<T: Send>(_: T) {}
let v = Cell::new(42);
let scope = scope!();
let r = scope.lend(&v);
assert_send(r); // 💥 Cell is not SyncImplementations§
Trait Implementations§
Source§impl<T: Error + ?Sized> Error for Ref<T>
impl<T: Error + ?Sized> Error for Ref<T>
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl<T: Ord + ?Sized> Ord for Ref<T>
impl<T: Ord + ?Sized> Ord for Ref<T>
Source§impl<T: PartialOrd + ?Sized> PartialOrd for Ref<T>
impl<T: PartialOrd + ?Sized> PartialOrd for Ref<T>
impl<T: Eq + ?Sized> Eq for Ref<T>
impl<T: Sync + ?Sized> Send for Ref<T>
impl<T: Sync + ?Sized> Sync for Ref<T>
Auto Trait Implementations§
impl<T> Freeze for Ref<T>where
T: ?Sized,
impl<T> RefUnwindSafe for Ref<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Unpin for Ref<T>where
T: ?Sized,
impl<T> UnsafeUnpin for Ref<T>where
T: ?Sized,
impl<T> UnwindSafe for Ref<T>where
T: RefUnwindSafe + ?Sized,
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