1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/// the point of this trait, is allow you to use, free functions, in composing manner 
///without being difficult to read with lots of nested parethensis
trait FreeFunPiper : Sized {
   #[inline(always)] 
     fn pipe<U,Fun>(self, f: Fun) -> U 
		where 
		 Fun : FnOnce(Self) -> U,
         U : Sized
    {
        f(self)
    }

	///all function 
   #[inline(always)] 
     fn pipe2<U,A,Fun>(self, f: Fun, a : A) -> U 
		where 
		 Fun : FnOnce(Self,A) -> U,
         U : Sized
    {
        f(self,a)
    }

   #[inline(always)] 
     fn pipe3<A,B,U,Fun>(self, f : Fun,
                               a : A,
                               b : B) -> U 
		where 
		 Fun : FnOnce(Self,A,B) -> U 
    {
        f(self,a,b)
    }

   #[inline(always)] 
     fn pipe4<A,B,C,U,Fun>(self, f : Fun,
                                 a : A,
                                 b : B,
                                 c : C) -> U 
		where 
		 Fun : FnOnce(Self,A,B,C) -> U 
    {
        f(self,a,b,c)
    }

   #[inline(always)] 
     fn pipe5<A,B,C,D,U,Fun>(self, f : Fun,
                                   a : A,
                                   b : B, 
                                   c : C,
                                   d : D) -> U 
		where 
		 Fun : FnOnce(Self,A,B,C,D) -> U 
    {
        f(self,a,b,c,d)
    }
///truthfully if you need more data than this 
///you have a real problem, you should probably merge some
///arguments under a structure
   #[inline(always)] 
     fn pipe6<A,B,C,D,E,U,Fun>(self, f : Fun,
                                     a : A, 
                                     b : B, 
                                     c : C, 
                                     d : D,
                                     e : E) -> U 
		where 
		 Fun : FnOnce(Self,A,B,C,D,E) -> U 
    {
        f(self,a,b,c,d,e)
    } 
}
//add piper trait to nearly every type that it can 
impl<T> FreeFunPiper for T where T : Sized {}

///this trait allows you to use functions, 
///that might normally might not be chainable, 
///using pipes from above trait!
///in theory using this should be no slower than 
///pipe because, move ellision should eliminate most of the moves.
///making pipm chaining just as fast explicit pipe writers 
trait FreeFunPipModer : Sized {

   #[inline(always)] 
     fn pipm<Fun>(mut self, f: Fun) -> Self 
		where 
		 Fun : FnOnce(&mut Self) 
    {
        f(&mut self);
            self
    }

   #[inline(always)] 
     fn pipm2<A,Fun>(mut self, f: Fun, a : A) -> Self 
		where 
		 Fun : FnOnce(&mut Self,A) 
    {
        f(&mut self,a);
            self
    }

   #[inline(always)] 
     fn pipm3<A,B,Fun>(mut self, f : Fun,
                               a : A,
                               b : B) -> Self 
		where 
		 Fun : FnOnce(&mut Self,A,B) 
    {
        f(&mut self,a,b);
            self
    }

   #[inline(always)] 
     fn pipm4<A,B,C,Fun>(mut self, f : Fun,
                                 a : A,
                                 b : B,
                                 c : C) -> Self 
		where 
		 Fun : FnOnce(&mut Self,A,B,C) 
    {
        f(&mut self,a,b,c);
            self
    }

   #[inline(always)] 
     fn pipm5<A,B,C,D,Fun>(mut self, f : Fun,
                                   a : A,
                                   b : B, 
                                   c : C,
                                   d : D) -> Self 
		where 
		 Fun : FnOnce(&mut Self,A,B,C,D) 
    {
        f(&mut self,a,b,c,d);
            self
    }
///truthfully if you need more data than this 
///you have a real problem, you should probably merge some
///arguments under a structure
   #[inline(always)] 
     fn pipm6<A,B,C,D,E,Fun>(mut self, f : Fun,
                                     a : A, 
                                     b : B, 
                                     c : C, 
                                     d : D,
                                     e : E) -> Self 
		where 
		 Fun : FnOnce(&mut Self,A,B,C,D,E) 
    {
        f(&mut self,a,b,c,d,e);
        self

    } 
}
///blanket implement, because is really only limited,
///by the fact that T must be sized to be passed or returned by value.
impl<T> FreeFunPipModer for T where T : Sized {}