pl-lens
This Rust library provides support for lenses, which are a mechanism in functional programming for focusing on a part of a complex data structure.
Usage
Add a dependency to your Cargo.toml
:
[]
= "1.0"
Then, in your crate:
// To use the `derive(Lenses)` macro
use Lenses;
// To use the `lens!` macro
use lens;
// To bring trait methods like `get_ref` and `set` into scope
use ;
Examples
A Lens
can be used to transform a conceptually-immutable data structure by changing only a portion of the data. Let's demonstrate with an example:
let p0 = Person ;
assert_eq!;
assert_eq!;
let p1 = lens!.set;
assert_eq!;
assert_eq!;
License
pl-lens
is distributed under an MIT license. See LICENSE for more details.