Trait RowSource

Source
pub trait RowSource
where Self::Rows: RowSet<Item = Self::Item>, for<'a> &'a <Self::Rows as RowSet>::Target: IntoIterator<Item = &'a Self::Item>,
{ type Item; type Rows; // Required method fn get(&self) -> Self::Rows; }
Available on crate feature wiremock only.
Expand description

Provide a collection of objects on demand.

This trait generalises the idea of “something that can provide data to query”. It’s important to note that the data it contains is owned, and is therefore guaranteed to survive for as long as needed, in particular for the life of the query. For correctness, it is expected that the returned data is a snapshot that will not change.

The reason for this definition is to make it possible to return views of data without copying, where that makes sense. For example using Arc<Vec<T>> as a RowSource does not entail copying data. It’s possible to define mutable types that generate snapshots on demand which also implement RowSource, if you need your test data to evolve.

The main drawback of this definition is that supporting bare containers becomes very expensive. Vec<T> is defined to be a RowSource, but the entire Vec must be copied for every call to get.

The "clone-replace" feature enables a mutable RowSource using a clone_replace::CloneReplace. Your test code is free to hold a reference to, and mutate, the CloneReplace wrapped collection. Each query will get an Arc<T> of a snapshot of the state of the collection at the start of the query. You can also extract a single Vec<T> field from a struct and serve that using CloneReplaceFieldSource. When both "clone-replace" and "persian-rug" are enabled, you can combine a CloneReplace and a persian_rug::Context using a CloneReplacePersianRugTableSource to create a RowSource for a single type inside the shared state, which remains mutable.

Required Associated Types§

Source

type Item

The type of the objects this provides.

Source

type Rows

The type of the collection this provides.

Required Methods§

Source

fn get(&self) -> Self::Rows

Return a new, owned collection of objects, which should now remain immutable.

Implementations on Foreign Types§

Source§

impl<T> RowSource for Arc<Vec<T>>

Source§

type Item = T

Source§

type Rows = Arc<Vec<T>>

Source§

fn get(&self) -> Self::Rows

Source§

impl<T> RowSource for CloneReplace<Vec<T>>

Source§

type Item = T

Source§

type Rows = Arc<Vec<T>>

Source§

fn get(&self) -> Self::Rows

Source§

impl<T: Clone> RowSource for Vec<T>

Source§

type Item = T

Source§

type Rows = Vec<T>

Source§

fn get(&self) -> Self::Rows

Implementors§

Source§

impl<C, F, U> RowSource for CloneReplacePersianRugTableSource<F, C>
where F: Fn(&Arc<C>) -> TableIterator<'_, U> + Clone, for<'a> &'a PersianRugTable<Arc<C>, F>: IntoIterator<Item = &'a U>, C: Context + Owner<U>, U: Contextual<Context = C>,

Source§

type Item = U

Source§

type Rows = PersianRugTable<Arc<C>, F>

Source§

impl<F, T, U> RowSource for CloneReplaceFieldSource<F, T>
where F: Fn(&T) -> &Vec<U> + Clone,

Source§

type Item = U

Source§

type Rows = ArcField<F, T>