Struct salsa_2022::routes::Routes
source · [−]pub struct Routes<DB: HasJars> { /* private fields */ }
Expand description
The “routes” structure is used to navigate the database.
The database contains a number of jars, and each jar contains a number of ingredients.
When the database is created, it creates each jar in turn.
Each jar then creates its ingredients.
Each ingredient is registered with the database by invoking the Routes::push
method.
This method assigns it a unique IngredientIndex
and stores some callbacks indicating
how to find the ingredient later based only on the index.
Implementations
sourceimpl<DB: HasJars> Routes<DB>
impl<DB: HasJars> Routes<DB>
sourcepub fn push<I>(
&mut self,
route: impl Fn(&DB::Jars) -> &I + Send + Sync + 'static,
mut_route: impl Fn(&mut DB::Jars) -> &mut I + Send + Sync + 'static
) -> IngredientIndexwhere
I: Ingredient<DB> + IngredientRequiresReset + 'static,
pub fn push<I>(
&mut self,
route: impl Fn(&DB::Jars) -> &I + Send + Sync + 'static,
mut_route: impl Fn(&mut DB::Jars) -> &mut I + Send + Sync + 'static
) -> IngredientIndexwhere
I: Ingredient<DB> + IngredientRequiresReset + 'static,
Adds a new ingredient into the ingredients table, returning
the IngredientIndex
that can be used in a DatabaseKeyIndex
.
This index can then be used to fetch the “route” so that we can
dispatch calls to maybe_changed_after
.
Parameters
requires_reset
– if true, theIngredient::reset_for_new_revision
method will be called on this ingredient at each new revision. See that method for more information.route
– a closure which, given a database, will identify the ingredient. This closure will be invoked to dispatch calls tomaybe_changed_after
.mut_route
– a closure which identifies the ingredient in a mut database.
sourcepub fn route(
&self,
index: IngredientIndex
) -> &dyn Fn(&DB::Jars) -> &dyn Ingredient<DB>
pub fn route(
&self,
index: IngredientIndex
) -> &dyn Fn(&DB::Jars) -> &dyn Ingredient<DB>
Given an ingredient index, return the “route”
(a function that, given a &Jars
, returns the ingredient).
sourcepub fn route_mut(
&self,
index: IngredientIndex
) -> &dyn Fn(&mut DB::Jars) -> &mut dyn Ingredient<DB>
pub fn route_mut(
&self,
index: IngredientIndex
) -> &dyn Fn(&mut DB::Jars) -> &mut dyn Ingredient<DB>
Given an ingredient index, return the “mut route”
(a function that, given an &mut Jars
, returns the ingredient).
sourcepub fn reset_routes(
&self
) -> impl Iterator<Item = &dyn Fn(&mut DB::Jars) -> &mut dyn Ingredient<DB>> + '_
pub fn reset_routes(
&self
) -> impl Iterator<Item = &dyn Fn(&mut DB::Jars) -> &mut dyn Ingredient<DB>> + '_
Returns the mut routes for ingredients that need to be reset at the start of each revision.