pub struct OptionHasOne<T>(/* private fields */);
Expand description
An optional “has-one association”.
It works exactly like HasOne
except it doesn’t error if the association doesn’t get loaded.
The value doesn’t get loaded it defaults to None
.
§Example
You can find a complete example of OptionHasMany
here.
§Attributes
It supports the same attributes as HasOne
.
§Errors
try_unwrap
will never error. If the association wasn’t loaded or wasn’t found it will
return Ok(None)
.
Implementations§
Source§impl<T> OptionHasOne<T>
impl<T> OptionHasOne<T>
Sourcepub fn try_unwrap(&self) -> Result<&Option<T>, Error>
pub fn try_unwrap(&self) -> Result<&Option<T>, Error>
Borrow the loaded value. If the value has not been loaded it will return Ok(None)
. It
will not error.
Trait Implementations§
Source§impl<T> Association<T> for OptionHasOne<Box<T>>
impl<T> Association<T> for OptionHasOne<Box<T>>
Source§fn loaded_child(&mut self, child: T)
fn loaded_child(&mut self, child: T)
Store the loaded child on the association.
Source§fn assert_loaded_otherwise_failed(&mut self)
fn assert_loaded_otherwise_failed(&mut self)
The association should have been loaded by now, if not store an error inside the
association (if applicable for the particular association).
Source§impl<T> Association<T> for OptionHasOne<T>
impl<T> Association<T> for OptionHasOne<T>
Source§fn loaded_child(&mut self, child: T)
fn loaded_child(&mut self, child: T)
Store the loaded child on the association.
Source§fn assert_loaded_otherwise_failed(&mut self)
fn assert_loaded_otherwise_failed(&mut self)
The association should have been loaded by now, if not store an error inside the
association (if applicable for the particular association).
Source§impl<T: Clone> Clone for OptionHasOne<T>
impl<T: Clone> Clone for OptionHasOne<T>
Source§fn clone(&self) -> OptionHasOne<T>
fn clone(&self) -> OptionHasOne<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T: Debug> Debug for OptionHasOne<T>
impl<T: Debug> Debug for OptionHasOne<T>
Source§impl<T> Default for OptionHasOne<T>
impl<T> Default for OptionHasOne<T>
Source§impl<T: Ord> Ord for OptionHasOne<T>
impl<T: Ord> Ord for OptionHasOne<T>
Source§fn cmp(&self, other: &OptionHasOne<T>) -> Ordering
fn cmp(&self, other: &OptionHasOne<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq> PartialEq for OptionHasOne<T>
impl<T: PartialEq> PartialEq for OptionHasOne<T>
Source§impl<T: PartialOrd> PartialOrd for OptionHasOne<T>
impl<T: PartialOrd> PartialOrd for OptionHasOne<T>
impl<T: Eq> Eq for OptionHasOne<T>
impl<T> StructuralPartialEq for OptionHasOne<T>
Auto Trait Implementations§
impl<T> Freeze for OptionHasOne<T>where
T: Freeze,
impl<T> RefUnwindSafe for OptionHasOne<T>where
T: RefUnwindSafe,
impl<T> Send for OptionHasOne<T>where
T: Send,
impl<T> Sync for OptionHasOne<T>where
T: Sync,
impl<T> Unpin for OptionHasOne<T>where
T: Unpin,
impl<T> UnwindSafe for OptionHasOne<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.