lens-rs

lens implemented in rust

Example

```rust use lens::; use lens_derive::;

[derive(Optic, Review, Prism, Debug)]

enum AnEnum { A(T, i32), #[optic] B(T), }

[derive(Optic, Lens, Debug)]

struct Foo { #[optic] a: i32, #[optic] b: i32, }

fn test1() -> Option<()> { let mut nested: ResultOk.Ok).review((1, 2)); *optics!(Ok.Ok.0).pmmut(&mut nested)? += 1; asserteq!(optics!(Ok.Ok.0).pm(nested)?, 2);

let mut x = (1, (2, (3, 4)));
*optics!(_1._1._1).view_mut(&mut x) *= 2;
assert_eq!(optics!(_1._1._1).view(x), 8);

let mut x: (_, Result<_, ()>) = (1, Ok((2, 3)));
*optics!(_1._Ok._1).pm_mut(&mut x)? *= 2;
assert_eq!(optics!(_1._Ok._1).pm(x)?, 6);

let mut x = (1, vec![Some((2, 3)), None]);
optics!(_1.Mapped._Some._0)
    .traverse_mut(&mut x)
    .into_iter()
    .for_each(|i| *i += 1);
assert_eq!(optics!(_1.Mapped._Some._0).traverse(x), vec![3]);

Some(())

}

fn test2() -> Option<()> { let x = optics!(Some.B).review(Foo { a: 3, b: 2, }); asserteq!(optics!(Some.B.b).pm(x)?, 2);

Some(())

} ```