use std::sync::Arc; use crate::lenses::{Lens, LensView}; use super::lens::FuncLens; #[derive(Clone)] pub struct ToInner(Arc 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: Arc 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(Arc::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, Arc::new(setter))) } }