Skip to main content

ThenLoad

Struct ThenLoad 

Source
pub struct ThenLoad<P: View, C: View, K> { /* private fields */ }
Expand description

One level of a load path: fetch C for a set of P, keyed, batched and deduplicated — plus the levels hanging off it.

Generated then_load::…() functions return one of these. It is a Mod over the parent’s ModelSelect, so it drops into a query tuple like any other mod; then is what makes it a path rather than a single level.

The three function pointers are the model-specific half — which keys to take off the parents, how to filter the child query by them, how to attach the results — and they are function pointers rather than closures because generated code has nothing to capture, which keeps this type Send + Sync without a bound in sight.

Implementations§

Source§

impl<P, C, K> ThenLoad<P, C, K>
where P: View, C: View, K: Ord + Clone + Send + Sync + 'static,

Source

pub fn new( keys: fn(&[P::Row]) -> Vec<K>, key_filter: fn(Vec<K>, &mut ModelSelect<C>), attach: fn(&mut [P::Row], Vec<C::Row>), ) -> Self

Assemble a level. Generated code calls this; the three arguments are the parent keys, the child-query filter and the attachment.

Source

pub fn then(self, deeper: impl IntoLoader<C::Row>) -> Self

Hang another level off this one: load deeper over the children this level fetched, before they are attached to their parents.

Typed by the child model — only a loader over C::Row fits — so the path is checked at the call site rather than spelled in a string.

Source

pub fn with( self, shape: impl Fn(&mut ModelSelect<C>) + Send + Sync + 'static, ) -> Self

Shape this level’s query: the closure runs on every batch query, after the key filter.

A closure rather than a mod because a mod is consumed when it is applied and there may be many batches — and because a query is re-issued every time the parent query runs. Anything that applies to a ModelSelect goes in it: a filter, an order, a Layer 1 mod, or a preload of the child’s own to-one relation.

posts::then_load::user()
    .with(|q| users::is_active().eq(true).apply(q))
Source

pub fn batch(self, keys: usize) -> Self

Override KEY_BATCH for this level.

§Panics

If keys is zero: a batch of no keys makes no progress, and silently substituting a size would hide the caller’s mistake.

Trait Implementations§

Source§

impl<P: View, C: View, K> Debug for ThenLoad<P, C, K>

Source§

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

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

impl<P, C, K> IntoLoader<<P as View>::Row> for ThenLoad<P, C, K>
where P: View, C: View, K: Ord + Clone + Send + Sync + 'static,

Source§

fn into_loader(self) -> Loader<P::Row>

The loader payload this level runs.
Source§

impl<P, C, K> Mod<ModelSelect<P>> for ThenLoad<P, C, K>
where P: View, C: View, K: Ord + Clone + Send + Sync + 'static,

Source§

fn apply(self, q: &mut ModelSelect<P>)

Apply this modification to q.

Auto Trait Implementations§

§

impl<P, C, K> !RefUnwindSafe for ThenLoad<P, C, K>

§

impl<P, C, K> !UnwindSafe for ThenLoad<P, C, K>

§

impl<P, C, K> Freeze for ThenLoad<P, C, K>

§

impl<P, C, K> Send for ThenLoad<P, C, K>

§

impl<P, C, K> Sync for ThenLoad<P, C, K>

§

impl<P, C, K> Unpin for ThenLoad<P, C, K>

§

impl<P, C, K> UnsafeUnpin for ThenLoad<P, C, K>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.