bad-optics/src/fns.rs

62 lines
1.4 KiB
Rust
Raw Normal View History

2021-11-05 15:55:49 +00:00
use crate::{
lenses::{LensOver, LensView},
Optics,
};
2021-11-05 14:22:59 +00:00
2021-11-05 15:55:49 +00:00
impl<L, A> std::ops::FnOnce<(A,)> for Optics<L>
2021-11-05 14:22:59 +00:00
where
L: LensView<A>,
{
type Output = L::Field;
extern "rust-call" fn call_once(self, args: (A,)) -> Self::Output {
2021-11-11 10:39:47 +00:00
L::view(&self.0, args.0)
2021-11-05 14:22:59 +00:00
}
}
2021-11-05 15:55:49 +00:00
impl<L, A> std::ops::FnMut<(A,)> for Optics<L>
2021-11-05 14:22:59 +00:00
where
L: LensView<A>,
{
extern "rust-call" fn call_mut(&mut self, args: (A,)) -> Self::Output {
2021-11-11 10:39:47 +00:00
L::view(&self.0, args.0)
2021-11-05 14:22:59 +00:00
}
}
2021-11-05 15:55:49 +00:00
impl<L, A> std::ops::Fn<(A,)> for Optics<L>
2021-11-05 14:22:59 +00:00
where
L: LensView<A>,
{
extern "rust-call" fn call(&self, args: (A,)) -> Self::Output {
2021-11-11 10:39:47 +00:00
L::view(&self.0, args.0)
2021-11-05 14:22:59 +00:00
}
}
2021-11-05 15:55:49 +00:00
impl<L, A, F> std::ops::FnOnce<(A, F)> for Optics<L>
2021-11-05 14:22:59 +00:00
where
L: LensOver<A>,
F: FnOnce(L::Field) -> L::Field,
{
type Output = A;
extern "rust-call" fn call_once(self, args: (A, F)) -> Self::Output {
2021-11-11 10:39:47 +00:00
L::over(&self.0, args.0, args.1)
2021-11-05 14:22:59 +00:00
}
}
2021-11-05 15:55:49 +00:00
impl<L, A, F> std::ops::FnMut<(A, F)> for Optics<L>
2021-11-05 14:22:59 +00:00
where
L: LensOver<A>,
F: FnOnce(L::Field) -> L::Field,
{
extern "rust-call" fn call_mut(&mut self, args: (A, F)) -> Self::Output {
2021-11-11 10:39:47 +00:00
L::over(&self.0, args.0, args.1)
2021-11-05 14:22:59 +00:00
}
}
2021-11-05 15:55:49 +00:00
impl<L, A, F> std::ops::Fn<(A, F)> for Optics<L>
2021-11-05 14:22:59 +00:00
where
L: LensOver<A>,
F: FnOnce(L::Field) -> L::Field,
{
extern "rust-call" fn call(&self, args: (A, F)) -> Self::Output {
2021-11-11 10:39:47 +00:00
L::over(&self.0, args.0, args.1)
2021-11-05 14:22:59 +00:00
}
}