bad-optics/src/lenses/identity.rs

22 lines
381 B
Rust
Raw Normal View History

2021-11-05 13:27:34 +00:00
use crate::{LensOver, LensTrait, LensView};
2021-11-05 11:03:17 +00:00
#[allow(non_camel_case_types)]
pub struct id;
2021-11-05 13:27:34 +00:00
impl LensTrait for id {}
impl<T> LensView<T> for id {
2021-11-05 11:03:17 +00:00
type Field = T;
fn view(thing: T) -> Self::Field {
thing
}
}
2021-11-05 13:27:34 +00:00
impl<T> LensOver<T> for id {
fn over<F>(thing: T, f: F) -> T
where
F: FnOnce(Self::Field) -> Self::Field,
{
2021-11-05 11:03:17 +00:00
f(thing)
}
}