use crate::lenses::{Lens, LensView}; use super::lens::FuncLens; pub struct ToInner(Box U>); impl LensView for ToInner { type Field = U; fn view(&self, thing: T) -> Self::Field { (self.0)(thing) } } /// Makes a lens that implements `LensView` with the provided function pub fn to_from_boxed(f: Box U>) -> Lens> { Lens(ToInner(f)) } /// Makes a lens that implements `LensView` with the provided function pub fn to(f: impl Fn(T) -> U + 'static) -> Lens> { Lens(ToInner(Box::new(f))) } impl Lens> { /// Makes a full lens that implements `LensView` and `LensOver` with the provided functions pub fn make_lens(self, setter: impl Fn(T, U) -> T + 'static) -> Lens> { Lens(FuncLens((self.0).0, Box::new(setter))) } }