use std::ops::{Div, Neg};
pub trait UnaryTransform<In, Out = In> {
fn apply(value: In) -> Out;
}
pub struct Ident;
impl<T> UnaryTransform<T> for Ident {
#[inline(always)]
fn apply(value: T) -> T {
value
}
}
pub struct Negate;
impl<T: Neg<Output = T>> UnaryTransform<T> for Negate {
#[inline(always)]
fn apply(value: T) -> T {
-value
}
}
pub struct Halve;
impl<T: Div<i64, Output = T>> UnaryTransform<T> for Halve {
#[inline(always)]
fn apply(value: T) -> T {
value / 2
}
}