pub enum Ref<V>where
V: ?Sized,{
None,
Owned(Arc<V>),
Borrowed(Weak<V>),
}Expand description
Holds a reference that is either None, Owned, or Borrowed.
It’s used to give a single field that can accept Option (without additional wrapping),
an owned value, or a reference to an owned value (to prevent unnecessary clones).
§Example
pub struct Button {
// Allows the Button to provide its own default, accept an owned value from a parent
// widget, or a reference to a layout.
pub layout: Ref<Layout>,
}Variants§
None
No value.
Owned(Arc<V>)
Owned data.
Borrowed(Weak<V>)
Borrowed data. Unlike Owned, this is not guaranteed to exist, as it only holds a weak reference to the Owned value. It should never be expected for the value to exist.
Implementations§
Source§impl<V> Ref<V>
impl<V> Ref<V>
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Returns true if this reference points to a value in memory.
Will always be true if the Ref is Owned, will always be None if the Ref is None,
but if it’s Borrowed, it will only return true if the borrowed value is still in memory.
Trait Implementations§
Auto Trait Implementations§
impl<V> Freeze for Ref<V>where
V: ?Sized,
impl<V> RefUnwindSafe for Ref<V>where
V: RefUnwindSafe + ?Sized,
impl<V> Send for Ref<V>
impl<V> Sync for Ref<V>
impl<V> Unpin for Ref<V>where
V: ?Sized,
impl<V> UnwindSafe for Ref<V>where
V: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.