pub trait RowSourcewhere
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;
}
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.