Struct trustfall_core::interpreter::DataContext
source · pub struct DataContext<Vertex> { /* private fields */ }
Expand description
A partial result of a Trustfall query within the interpreter defined in this module.
Implementations§
source§impl<Vertex> DataContext<Vertex>
impl<Vertex> DataContext<Vertex>
sourcepub fn active_vertex<V>(&self) -> Option<&V>where
Vertex: AsVertex<V>,
pub fn active_vertex<V>(&self) -> Option<&V>where Vertex: AsVertex<V>,
The vertex currently being processed.
For contexts passed to an Adapter
resolver method,
this is the vertex whose data needs to be resolved.
The active vertex may be None
when processing an @optional
part
of a Trustfall query whose data did not exist. In that case:
Adapter::resolve_property
must produceFieldValue::Null
for that context.Adapter::resolve_neighbors
must produce an empty iterator of neighbors such asBox::new(std::iter::empty())
for that context.Adapter::resolve_coercion
must produce afalse
coercion outcome for that context.
sourcepub fn map<Other>(
self,
mapper: &mut impl FnMut(Vertex) -> Other
) -> DataContext<Other>
pub fn map<Other>( self, mapper: &mut impl FnMut(Vertex) -> Other ) -> DataContext<Other>
Converts DataContext<Vertex>
to DataContext<Other>
by mapping each Vertex
to Other
.
If you are implementing an Adapter
for a data source,
you almost certainly should not be using this function.
You’re probably looking for DataContext::active_vertex()
instead.
sourcepub fn flat_map<T>(
self,
mapper: &mut impl FnMut(Vertex) -> Option<T>
) -> DataContext<T>
pub fn flat_map<T>( self, mapper: &mut impl FnMut(Vertex) -> Option<T> ) -> DataContext<T>
Map each Vertex
to Option<Other>
, thus converting Self
to DataContext<Other>
.
This is the DataContext
equivalent of Option::and_then
, which is also
referred to as “flat-map” in some languages.
If you are implementing an Adapter
for a data source,
you almost certainly should not be using this function.
You’re probably looking for DataContext::active_vertex()
instead.
source§impl<Vertex: Clone + Debug> DataContext<Vertex>
impl<Vertex: Clone + Debug> DataContext<Vertex>
pub fn new(vertex: Option<Vertex>) -> DataContext<Vertex>
Trait Implementations§
source§impl<Vertex: Clone> Clone for DataContext<Vertex>
impl<Vertex: Clone> Clone for DataContext<Vertex>
source§fn clone(&self) -> DataContext<Vertex>
fn clone(&self) -> DataContext<Vertex>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<Vertex: Debug> Debug for DataContext<Vertex>
impl<Vertex: Debug> Debug for DataContext<Vertex>
source§impl<'de, Vertex> Deserialize<'de> for DataContext<Vertex>where
Vertex: Debug + Clone + Serialize + DeserializeOwned,
impl<'de, Vertex> Deserialize<'de> for DataContext<Vertex>where Vertex: Debug + Clone + Serialize + DeserializeOwned,
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
source§impl<Vertex: PartialEq> PartialEq for DataContext<Vertex>
impl<Vertex: PartialEq> PartialEq for DataContext<Vertex>
source§impl<Vertex> Serialize for DataContext<Vertex>where
Vertex: Debug + Clone + Serialize + DeserializeOwned,
impl<Vertex> Serialize for DataContext<Vertex>where Vertex: Debug + Clone + Serialize + DeserializeOwned,
impl<Vertex: Eq> Eq for DataContext<Vertex>
Auto Trait Implementations§
impl<Vertex> RefUnwindSafe for DataContext<Vertex>where Vertex: RefUnwindSafe,
impl<Vertex> Send for DataContext<Vertex>where Vertex: Send,
impl<Vertex> Sync for DataContext<Vertex>where Vertex: Sync,
impl<Vertex> Unpin for DataContext<Vertex>where Vertex: Unpin,
impl<Vertex> UnwindSafe for DataContext<Vertex>where Vertex: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.