Crates.io | lens-rs_derive |
lib.rs | lens-rs_derive |
version | 0.3.2 |
source | src |
created_at | 2021-03-20 05:34:19.250466 |
updated_at | 2021-05-07 17:27:37.607826 |
description | macro to derive lens for data type |
homepage | |
repository | https://github.com/TOETOE55/lens-rs |
max_upload_size | |
id | 371273 |
size | 87,645 |
deriving lens for custom data types.
see the guide
#[derive(Debug, Lens)]
struct Baz<'a, A, B, C>{
#[optic(ref)]
a: &'a A, // can only take the immutable ref by optics::a
#[optic(mut)]
b: &'a mut B, // can take the mutable ref by optics::b
#[optic]
c: C // can mv it out by by optics::c
}
#[derive(Review, Prism, Debug)]
enum AnEnum<T> {
A(T, i32), // couldn't derive Prism or Review
#[optic]
B(T),
#[optic]
C,
#[optic]
D(),
#[optic]
E {},
}
#[derive(Lens, Debug)]
struct Foo {
#[optic] a: i32,
#[optic] b: i32,
}
fn test() -> Option<()> {
let x = Review::review(optics!(Some.B), Foo {
a: 3,
b: 2,
});
assert_eq!(x.preview(optics!(Some.B.b))?, 2);
Some(())
}
Lens
for enum.Prism
and Review
for the variant has more than one argument or has named field.