use crate::{lenses::LensView, Optics, OpticsTrait}; use super::lens::LensInner; pub struct ToInner(Box U>); impl OpticsTrait for ToInner {} 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>) -> Optics> { Optics(ToInner(f)) } /// Makes a lens that implements `LensView` with the provided function pub fn to(f: impl Fn(T) -> U + 'static) -> Optics> { Optics(ToInner(Box::new(f))) } impl Optics> { /// 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) -> Optics> { Optics(LensInner((self.0).0, Box::new(setter))) } }