Macro rovv::dyn_row [−][src]
dyn_row!() { /* proc-macro */ }
Example
A row with field a: String
fn with_field_a(r: row! { a: String, .. }) -> String { r.view(optics!(a)) } fn to_field_a() -> row! { a: String, .. } { Bar { a: "this is Bar".to_string(), c: 0, } } let foo = Foo { a: "this is Foo".to_string(), b: (), }; let bar = Bar { a: "this is Bar".to_string(), c: 0, }; assert_eq!(with_field_a(foo.clone()).as_str(), "this is Foo"); assert_eq!(with_field_a(bar.clone()).as_str(), "this is Bar");
A row may have field Some: String
row! { Some: String?, .. } dyn_row! { Some: String?, .. } // dynamic version of row!
A row have multiple fields _mapped: String
row! { _mapped: String*, .. } dyn_row! { _mapped: String*, .. }
A row with a mutable or immutable field:
row! { ref a: A, mut b: B, .. } dyn_row! { ref a: A, mut b: B, .. }
A row bound by lifetimes 'a
row! { <'a> ref a: A, mut b: B, .. } dyn_row! { <'a> ref a: A, mut b: B, .. }
In fact,
row! { <'a> ref a: A, mut b: B, c: C, .. }
isimpl LensRef<Optic![a], Image = A> + LensMut<Optic![b], Image = B> + Lens<Optic![c], Image = C> + 'a
dyn_row! { <'a> ref a: A, mut b: B, c: C, .. }
isdyn LensRef<Optic![a], Image = A> + LensMut<Optic![b], Image = B> + Lens<Optic![c], Image = C> + 'a
transform
dyn_row! { <'a> ref a: A, mut b: B, c: C, .. }
to
dyn LensRef<Optic![a], Image = A> + LensMut<Optic![b], Image = B> + Lens<Optic![c], Image = C> + 'a