Struct DynamicallyResolvedValue

Source
#[non_exhaustive]
pub struct DynamicallyResolvedValue<'a> { /* private fields */ }
Expand description

Indicates that a property’s value is dependent on another value in the query.

If VertexInfo::dynamically_required_property() is able to determine a value for the specified property, it returns a DynamicallyResolvedValue. The specified property’s value may be different in different query results, but the way in which it varies can be determined programmatically and can be resolved to a CandidateValue for each query result.

§Example

Consider the following query, which fetches emails where the sender also included their own address in the receipients:

{
    Email {
        contents @output

        sender {
            address @tag(name: "sender")
        }
        recipient {
            address @filter(op: "=", value: ["%sender"])
        }
    }
}

A naïve implementation of resolving the recipient edge would resolve all recipients for each email and rely on Trustfall to filter out recipient addresses that don’t match the sender’s address. This implementation is valid, but can be made faster.

To improve performance, the implementation could avoid loading all recipients and instead only load the recipient that matches the sender’s address (if any).

However, as the sender’s address varies from email to email, its value must be resolved dynamically, i.e. separately for each possible query result. Resolving the recipient edge might then look like this:

// Inside our adapter implementation:
// we use this method to resolve `recipient` edges.
fn resolve_recipient_edge<'a, V: AsVertex<Vertex> + 'a>(
    &self,
    contexts: ContextIterator<'a, V>,
    resolve_info: &ResolveEdgeInfo,
) -> ContextOutcomeIterator<'a, V, VertexIterator<'a, Vertex>> {
    if let Some(dynamic_value) = resolve_info.destination().dynamically_required_property("address") {
        // The query is looking for a specific recipient's address,
        // so let's look it up directly.
        dynamic_value.resolve_with(self, contexts, |vertex, candidate| {
            resolve_recipient_from_candidate_value(vertex, candidate)
        })
    } else {
        // No specific recipient address, use the general-case edge resolver logic.
        resolve_recipient_otherwise(contexts)
    }
}

Implementations§

Source§

impl<'a> DynamicallyResolvedValue<'a>

Source

pub fn resolve<'vertex, AdapterT: Adapter<'vertex>, V: AsVertex<AdapterT::Vertex> + 'vertex>( self, adapter: &AdapterT, contexts: ContextIterator<'vertex, V>, ) -> ContextOutcomeIterator<'vertex, V, CandidateValue<FieldValue>>

Source

pub fn resolve_with<'vertex, AdapterT: Adapter<'vertex>, V: AsVertex<AdapterT::Vertex> + 'vertex>( self, adapter: &AdapterT, contexts: ContextIterator<'vertex, V>, neighbor_resolver: impl FnMut(&AdapterT::Vertex, CandidateValue<FieldValue>) -> VertexIterator<'vertex, AdapterT::Vertex> + 'vertex, ) -> ContextOutcomeIterator<'vertex, V, VertexIterator<'vertex, AdapterT::Vertex>>

Trait Implementations§

Source§

impl<'a> Clone for DynamicallyResolvedValue<'a>

Source§

fn clone(&self) -> DynamicallyResolvedValue<'a>

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

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for DynamicallyResolvedValue<'a>

Source§

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

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

impl<'a> PartialEq for DynamicallyResolvedValue<'a>

Source§

fn eq(&self, other: &DynamicallyResolvedValue<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for DynamicallyResolvedValue<'a>

Source§

impl<'a> StructuralPartialEq for DynamicallyResolvedValue<'a>

Auto Trait Implementations§

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<V> AsVertex<V> for V
where V: Debug + Clone,

Source§

fn as_vertex(&self) -> Option<&V>

Dereference this value into a &V, if the value happens to contain a V. Read more
Source§

fn into_vertex(self) -> Option<V>

Consume self and produce the contained V, if one was indeed present. 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.