hetseq/
lib.rs

1#![cfg_attr(feature="nightly", feature(unsize, fn_traits, unboxed_closures))]
2
3#[cfg(feature = "par_iter")]
4extern crate rayon;
5
6#[cfg(feature = "shred")]
7extern crate shred;
8
9/// Convenient way to define heterogenous `List`
10#[macro_export]
11macro_rules! hlist {
12    () => {
13        List::new()
14    };
15    ($head:expr $(, $tail:expr)*) => {
16        hlist![$($tail),*].push($head)
17    };
18}
19
20/// Convenient way to define heterogenous `Queue`
21#[macro_export]
22macro_rules! hqueue {
23    ($($values:expr),*) => {
24        Queue::new()$(.push($values))*
25    };
26}
27
28/// Convenient way to define heterogenous `Queue`
29#[macro_export]
30macro_rules! HQueue {
31    () => {
32        Queue<()>
33    };
34    ($($types:path),*, $last:path) => {
35        Queue<(HQueue![$($types),*], $last)>
36    };
37}
38
39/// This macro can be used to define lambdas with syntax similar to rust's lambdas
40/// Arguments are bounded by traits
41/// Mainly to use with `Functor` and `Foldable`
42#[cfg(not(feature="nightly"))]
43#[macro_export]
44macro_rules! lambda {
45    {let $n:ident = |$($an:ident $(: $at:path)*),+| -> $o:ty { $($s:stmt);* }} => {
46
47        #[derive(Clone, Copy)]
48        #[allow(non_camel_case_types)]
49        pub struct $n;
50
51        #[allow(non_camel_case_types,unused_mut)]
52        impl<$($an: $($at)*,)+> $crate::HetFnOnce<($($an,)*)> for $n {
53            type Output = $o;
54            fn call_once(self, ($(mut $an,)*): ($($an,)*)) -> $o {
55                Self::call(&self, ($($an,)*))
56            }
57        }
58
59        #[allow(non_camel_case_types,unused_mut)]
60        impl<$($an: $($at)*,)*> $crate::HetFnMut<($($an,)*)> for $n {
61            fn call_mut(&mut self, ($(mut $an,)*): ($($an,)*)) -> $o {
62                Self::call(&self, ($($an,)*))
63            }
64        }
65
66        #[allow(non_camel_case_types,unused_mut)]
67        impl<$($an: $($at)*,)*> $crate::HetFn<($($an,)*)> for $n {
68            fn call(&self, ($(mut $an,)*): ($($an,)*)) -> $o {
69                $($s);*
70            }
71        }
72    };
73
74    {let $n:ident$(<$($p:ident $(: $pb:path)*),+>)*($($c:ident: $ct:ty)+) = |$($an:ident $(: $at:path)*),+| -> $o:ty { $($s:stmt);* }} => {
75
76        #[derive(Clone)]
77        #[allow(non_camel_case_types)]
78        pub struct $n<'a, $($($p: 'a),+)*>(::std::marker::PhantomData<&'a ()>, $($ct),+);
79
80        impl<'a, $($($p),+)*> $n<'a, $($($p),+)*>
81            where $($($p: 'a $( + $pb,)*)+)*
82        {
83            pub fn new($($c: $ct)+) -> Self {
84                $n(::std::marker::PhantomData, $($c),+)
85            }
86        }
87
88        #[allow(non_camel_case_types,unused_mut)]
89        impl<'a, $($an,)+ $($($p,)+)*> $crate::HetFnOnce<($($an,)*)> for $n<'a, $($($p),+)*>
90            where $($($an: $at,)*)+
91                  $($($p: 'a $( + $pb,)*)+)*
92        {
93            type Output = $o;
94            fn call_once(self, ($(mut $an,)*): ($($an,)*)) -> $o {
95                $crate::HetFn::call(&self, ($($an,)*))
96            }
97        }
98
99        #[allow(non_camel_case_types,unused_mut)]
100        impl<'a, $($an,)+ $($($p,)+)*> $crate::HetFnMut<($($an,)*)> for $n<'a, $($($p),+)*>
101            where $($($an: $at,)*)+
102                  $($($p: 'a $( + $pb,)*)+)*
103        {
104            fn call_mut(&mut self, ($(mut $an,)*): ($($an,)*)) -> $o {
105                $crate::HetFn::call(self, ($($an,)*))
106            }
107        }
108
109        #[allow(non_camel_case_types,unused_mut)]
110        impl<'a, $($an,)+ $($($p,)+)*> $crate::HetFn<($($an,)*)> for $n<'a, $($($p),+)*>
111            where $($($an: $at,)*)+
112                  $($($p: 'a $( + $pb,)*)+)*
113        {
114            fn call(&self, ($(mut $an,)*): ($($an,)*)) -> $o {
115                let $n(_, $(ref $c,)+) = *self;
116                $($s);*
117            }
118        }
119    };
120}
121
122
123mod by_ref;
124
125#[cfg(not(feature="nightly"))]
126mod f;
127
128mod fold;
129mod functor;
130mod len;
131mod list;
132mod num;
133mod try;
134mod queue;
135mod zip;
136
137#[cfg(feature = "par_iter")]
138mod par_iter;
139
140#[cfg(feature = "shred")]
141mod system_data;
142
143#[cfg(test)]
144mod tests;
145
146#[cfg(feature="nightly")]
147mod unsize_iter;
148
149pub use by_ref::ByRef;
150#[cfg(not(feature="nightly"))]
151pub use f::{HetFnOnce, HetFnMut, HetFn};
152pub use fold::Foldable;
153pub use functor::Functor;
154pub use len::Length;
155pub use list::{IntoList, List};
156pub use num::{Num, P, S, Z};
157pub use try::Try;
158pub use queue::{IntoQueue, Queue};
159pub use zip::Zip;
160
161#[cfg(feature="nightly")]
162pub use unsize_iter::{IntoRefIter, UnsizeRefIter, UnsizeRefIterator};
163
164
165pub mod prelude;