Skip to main content

HasOne

Struct HasOne 

Source
pub struct HasOne<T> { /* private fields */ }
Expand description

A lazily-loaded has-one association.

HasOne<T> wraps an optional T that is populated when the association is eagerly loaded (via include) or accessed through a generated relation accessor. Before loading, calling get panics.

This type appears as a field on model structs for has-one relations.

Implementations§

Source§

impl<T: Relation> HasOne<T>

Source

pub fn get(&self) -> &T

Returns a reference to the loaded associated record.

§Panics

Panics if the association has not been loaded.

Source

pub fn is_unloaded(&self) -> bool

Returns true if the association has not been loaded yet.

Source

pub fn unload(&mut self)

Clear the loaded value, returning this association to the unloaded state.

Trait Implementations§

Source§

impl<T: Clone> Clone for HasOne<T>

Source§

fn clone(&self) -> HasOne<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for HasOne<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for HasOne<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Relation> Load for HasOne<T>

Source§

type Output = HasOne<T>

The concrete type produced by load. Read more
Source§

fn ty() -> Type

Returns the stmt::Type that describes values of this type.
Source§

fn load(input: Value) -> Result<Self>

Deserialize a database Value into Self::Output. Read more
Source§

fn ty_relation() -> Type

Returns the stmt::Type used when this type appears as a relation target. The default delegates to ty().
Source§

fn load_relation(value: Value) -> Result<Self::Output, Error>

Deserialize a value that was loaded as a relation target. Read more
Source§

fn reload(target: &mut Self::Output, value: Value) -> Result<(), Error>

Reload the value in-place from a value returned by the database. Read more
Source§

impl<T: Relation> Relation for HasOne<T>

Source§

type Model = <T as Relation>::Model

The target model
Source§

type Expr = <T as Relation>::Expr

The target expression (e.g. Option<Model>)
Source§

type Query = <T as Relation>::Query

The query builder type for querying this relation’s target.
Source§

type Create = <T as Relation>::Create

Create builder type for this relation’s target model
Source§

type Many = <T as Relation>::Many

HasMany relation type
Source§

type ManyField<__Origin> = <T as Relation>::ManyField<__Origin>

The field accessor type used when this model appears as the “many” side of a has-many relation, parameterized by the origin model.
Source§

type One = <T as Relation>::One

The has-one relation wrapper type for this model.
Source§

type OneField<__Origin> = <T as Relation>::OneField<__Origin>

The field accessor type used when this model appears as the “one” side of a has-one relation, parameterized by the origin model.
Source§

type OptionOne = <T as Relation>::OptionOne

The optional has-one relation wrapper type. Used when the foreign key is nullable, making the association optional.
Source§

fn new_many_field<__Origin>( path: Path<__Origin, List<Self::Model>>, ) -> Self::ManyField<__Origin>

Construct a ManyField from a path targeting a list of the model.
Source§

fn field_name_to_id(name: &str) -> FieldId

Map a field name string to its FieldId. Read more
Source§

fn nullable() -> bool

Returns true if this relation target is nullable (i.e., wrapped in Option). The default is false.
Source§

fn new_create() -> Self::Create

Return a fresh, default-initialized create builder.

Auto Trait Implementations§

§

impl<T> Freeze for HasOne<T>

§

impl<T> RefUnwindSafe for HasOne<T>
where T: RefUnwindSafe,

§

impl<T> Send for HasOne<T>
where T: Send,

§

impl<T> Sync for HasOne<T>
where T: Sync,

§

impl<T> Unpin for HasOne<T>

§

impl<T> UnsafeUnpin for HasOne<T>

§

impl<T> UnwindSafe for HasOne<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more