main
annieversary 2021-11-17 16:39:51 +00:00
parent cc9c90202b
commit 3d8b58202d
1 changed files with 14 additions and 0 deletions

View File

@ -186,6 +186,20 @@ mod tests {
assert_eq!(l(hello, |v| v + 1), Hello { hey: 9 });
}
#[test]
fn can_make_lens_with_ref_for_field() {
// making a lens
let l = crate::field_lens_with_ref!(Hello, hey);
let hello = Hello { hey: 8 };
// as ref
assert_eq!(l(&hello), 8);
// as move
assert_eq!(l(hello.clone()), 8);
assert_eq!(l(hello, |v| v + 1), Hello { hey: 9 });
}
#[test]
fn can_make_lens_out_of_funcs() {
// making a lens