Skip to main content

Related

Struct Related 

Source
pub struct Related<T: Model> { /* private fields */ }
Expand description

A related single object (many-to-one or one-to-one).

This wrapper can be in one of three states:

  • Empty: no relationship (fk_value is None)
  • Unloaded: has FK value but not fetched yet (fk_value is Some, loaded unset)
  • Loaded: the object has been fetched and cached (loaded set)

Implementations§

Source§

impl<T: Model> Related<T>

Source

pub const fn empty() -> Self

Create an empty relationship (null FK, not loaded).

Source

pub fn from_fk(fk: impl Into<Value>) -> Self

Create from a foreign key value (not yet loaded).

Source

pub fn loaded(obj: T) -> Self

Create with an already-loaded object.

Source

pub fn get(&self) -> Option<&T>

Get the loaded object (None if not loaded or loaded as null).

Source

pub fn is_loaded(&self) -> bool

Check if the relationship has been loaded (including loaded-null).

Source

pub fn is_empty(&self) -> bool

Check if the relationship is empty (null FK).

Source

pub fn fk(&self) -> Option<&Value>

Get the foreign key value (if present).

Source

pub fn set_loaded(&self, obj: Option<T>) -> Result<(), Option<T>>

Set the loaded object (internal use by query system).

Trait Implementations§

Source§

impl<T: Model + Clone> Clone for Related<T>

Source§

fn clone(&self) -> Self

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: Model + Debug> Debug for Related<T>

Source§

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

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

impl<T: Model> Default for Related<T>

Source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for Related<T>
where T: Model + Deserialize<'de>,

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Serialize for Related<T>
where T: Model + Serialize,

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for Related<T>

§

impl<T> RefUnwindSafe for Related<T>

§

impl<T> Send for Related<T>

§

impl<T> Sync for Related<T>

§

impl<T> Unpin for Related<T>
where T: Unpin,

§

impl<T> UnwindSafe for Related<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: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
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> ModelDump for T
where T: Serialize,

Source§

fn model_dump(&self, options: DumpOptions) -> Result<Value, Error>

Serialize a model to a JSON value. Read more
Source§

fn model_dump_json(&self) -> Result<String, Error>

Serialize a model to a JSON string with default options.
Source§

fn model_dump_json_pretty(&self) -> Result<String, Error>

Serialize a model to a pretty-printed JSON string.
Source§

fn model_dump_json_with_options( &self, options: DumpOptions, ) -> Result<String, Error>

Serialize a model to a JSON string with full options support. Read more
Source§

impl<T> ModelValidate for T

Source§

fn model_validate( input: impl Into<ValidateInput>, options: ValidateOptions, ) -> Result<T, ValidationError>

Create and validate a model from input. Read more
Source§

fn model_validate_json(json: &str) -> ValidateResult<Self>

Create and validate a model from JSON string with default options.
Source§

fn model_validate_dict(dict: HashMap<String, Value>) -> ValidateResult<Self>

Create and validate a model from a HashMap with default options.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,