Crate scrapmetal

Source
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 the F: 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.
EverywhereBut
Recursively perform a transformation in a bottom up manner across a complete data structure.
MutateEverything
Recursively perform a query in a top-down, left-to-right manner across a data structure. The M: GenericMutate<R> queries individual values, while the F: 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 a U. It can be called on values of any type T, not just on values of type U, so it requires a default R value for when it is called on values which are not a T.
Query
A query non-destructively creates some value R from references to a U. It can be called on values of any type T, not just on values of type U, so it requires a default R value for when it is called on values which are not a T.
Transformation
A transformation takes some value U and returns a new, transformed version of it. It can be called on values of any type T, not just on values of type U, in which case it is simply the identity function.

Traits§

GenericMutate
A similar work around as GenericTransform, but mutating in place and optionally returning some query type, rather than taking self and returning the same Self type.
GenericQuery
A similar work around as GenericTransform, but returning a query type, rather than the same type. This is roughly equivalent to for<T> FnMut(&T) -> R.
GenericTransform
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 type F: for<T> FnMut(T) -> T rather than F: GenericTransform but Rust doesn’t support them yet (ever?).
Term
A Term is a value that can be mapped or queried.