wacky_traits 2.0.0

Defines some traits
Documentation


/// Fn(Input)->Output
pub trait Mapper<Input>{
    type Output;
    fn map(&self,value:Input)->Self::Output;
}

/// Fn(Input)->Output is Mapper<Input>
/// 
/// due to this, rustc will say "no T:Mapper" as "expect Fn, found T"
impl<'a,Input,Output,TFn:Fn(Input)->Output> Mapper<Input> for TFn {
    type Output = Output;
    //type TOutput = TOut;
    fn map(&self,value:Input)->Self::Output {
        (*self)(value)
    }
}

/// FnOnce(Input)->Output
pub trait MapperOnce<Input>{
    type Output;
    fn map_once(self,value:Input)->Self::Output;
}

/// FnOnce(Input)->Output is MapperOnce<Input>
/// 
/// due to this, rustc will say "no T:MapperOnce" as "expect FnOnce, found T"
impl<'a,Input,Output,TFn:FnOnce(Input)->Output> MapperOnce<Input> for TFn {
    type Output = Output;
    //type TOutput = TOut;
    fn map_once(self,value:Input)->Self::Output {
        (self)(value)
    }
}