Query

Trait Query 

Source
pub trait Query<V> {
    // Required methods
    fn program(&self) -> &Program;
    fn execute_with_context(
        &self,
        documents: &mut Documents,
        context: &DynamicContext<'_>,
    ) -> Result<V>;

    // Provided methods
    fn static_context(&self) -> &StaticContext { ... }
    fn dynamic_context_builder(
        &self,
        documents: &Documents,
    ) -> DynamicContextBuilder<'_> { ... }
    fn map<T, F>(self, f: F) -> MapQuery<V, T, Self, F>
       where Self: Sized,
             F: Fn(V, &mut Documents, &DynamicContext<'_>) -> Result<T> + Clone { ... }
    fn execute(
        &self,
        documents: &mut Documents,
        item: impl Itemable,
    ) -> Result<V> { ... }
    fn execute_build_context(
        &self,
        documents: &mut Documents,
        build: impl FnOnce(&mut DynamicContextBuilder<'_>),
    ) -> Result<V> { ... }
}
Expand description

A query that can be executed against an Itemable

It gives back a result of type V

Required Methods§

Source

fn program(&self) -> &Program

Get the program for the query

Source

fn execute_with_context( &self, documents: &mut Documents, context: &DynamicContext<'_>, ) -> Result<V>

Execute the query against a dynamic context

You can construct one using a DynamicContextBuilder

Provided Methods§

Source

fn static_context(&self) -> &StaticContext

Get the static context for the query.

Source

fn dynamic_context_builder( &self, documents: &Documents, ) -> DynamicContextBuilder<'_>

Get a dynamic context builder for the query, configured with the query’s static context and the document’s documents.

You can use this if you want to construct your own dynamic context to use with execute_with_context.

Source

fn map<T, F>(self, f: F) -> MapQuery<V, T, Self, F>
where Self: Sized, F: Fn(V, &mut Documents, &DynamicContext<'_>) -> Result<T> + Clone,

Map the the result of the query to a different type.

You need to provide a function that takes the result of the query, the document, and the item, and returns a new result.

Source

fn execute(&self, documents: &mut Documents, item: impl Itemable) -> Result<V>

Excute the query against an itemable

Source

fn execute_build_context( &self, documents: &mut Documents, build: impl FnOnce(&mut DynamicContextBuilder<'_>), ) -> Result<V>

Execute a query with a specific dynamic context.

This is useful if you want to build a dynamic context with specific settings (such as variables), and then execute a query against it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Query<Sequence> for SequenceQuery

Source§

impl<V, F> Query<Option<V>> for OptionQuery<V, F>
where F: Convert<V>,

Source§

impl<V, F> Query<Vec<V>> for ManyQuery<V, F>
where F: Convert<V>,

Source§

impl<V, F> Query<V> for OneQuery<V, F>
where F: Convert<V>,

Source§

impl<V, T, Q: Query<V> + Sized, F> Query<T> for MapQuery<V, T, Q, F>
where F: Fn(V, &mut Documents, &DynamicContext<'_>) -> SpannedResult<T> + Clone,