Expand description
Scrap Your Boilerplate!
This crate provides the traversing, transforming, and querying helpers and combinators from the Haskell paper “Scrap Your Boilerplate: A Practical Design Pattern for Generic Programming” by Lämmel and Peyton Jones to Rust.
Structs§
- Everything
- Recursively perform a query in a top-down, left-to-right manner across a
data structure. The
Q: Query<R>
queries individual values, while theF: FnMut(R, R) -> R
joins the results of multiple queries into a single result. - Everywhere
- Recursively perform a transformation in a bottom up manner across a complete data structure.
- Everywhere
But - Recursively perform a transformation in a bottom up manner across a complete data structure.
- Mutate
Everything - Recursively perform a query in a top-down, left-to-right manner across a
data structure. The
M: GenericMutate<R>
queries individual values, while theF: FnMut(R, R) -> R
joins the results of multiple queries into a single result. - Mutation
- A mutation creates some value
R
from mutable references to aU
. It can be called on values of any typeT
, not just on values of typeU
, so it requires a defaultR
value for when it is called on values which are not aT
. - Query
- A query non-destructively creates some value
R
from references to aU
. It can be called on values of any typeT
, not just on values of typeU
, so it requires a defaultR
value for when it is called on values which are not aT
. - Transformation
- A transformation takes some value
U
and returns a new, transformed version of it. It can be called on values of any typeT
, not just on values of typeU
, in which case it is simply the identity function.
Traits§
- Generic
Mutate - A similar work around as
GenericTransform
, but mutating in place and optionally returning some query type, rather than takingself
and returning the sameSelf
type. - Generic
Query - A similar work around as
GenericTransform
, but returning a query type, rather than the same type. This is roughly equivalent tofor<T> FnMut(&T) -> R
. - Generic
Transform - Work around Rust’s lack of higher-rank type polymorphism with a trait that
has a generic
fn transform<T>
method. Essentially, we’d really prefer taking arguments of typeF: for<T> FnMut(T) -> T
rather thanF: GenericTransform
but Rust doesn’t support them yet (ever?). - Term
- A
Term
is a value that can be mapped or queried.