bad-optics/src/lenses/identity.rs

26 lines
429 B
Rust
Raw Normal View History

2021-11-05 15:55:49 +00:00
use crate::{
lenses::{LensOver, LensView},
OpticsTrait,
};
2021-11-05 11:03:17 +00:00
#[allow(non_camel_case_types)]
2021-11-05 14:22:59 +00:00
#[derive(Clone, Copy)]
2021-11-05 11:03:17 +00:00
pub struct id;
2021-11-05 15:55:49 +00:00
impl OpticsTrait for id {}
2021-11-05 13:27:34 +00:00
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)
}
}