Skip to main content

lens

Macro lens 

Source
macro_rules! lens {
    ($($model:ident)::+ . $($field:ident).+) => { ... };
}
Expand description

Build a Lens from a model and a field, or a chain of embedded fields.

lens!(User.name) is the path User::fields().name() paired with |user| &user.name. A chain through a relation does not compile: a relation’s records are not part of the row.

let name: Lens<User, String> = lens!(User.name);
let seo: Lens<Post, Seo> = lens!(Post.seo); // an embedded value, whole
let title: Lens<Post, String> = lens!(Post.seo.title); // an embedded struct's field
let qualified = lens!(blog::Post.title);