#[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 copy 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<'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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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> StructuralEq for DynamicallyResolvedValue<'a>

source§

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<V> AsVertex<V> for Vwhere 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 Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

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

§

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

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

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

§

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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.