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
pub mod then;
pub mod facet;
pub mod map;
pub use facet::{facet, Facet};
pub use map::{map, Map};
use then::Then;
#[cfg(feature = "std")]
pub use facet::{facet_map, FacetMap};
extern crate alloc;
use alloc::boxed::Box;
#[cfg(feature = "async")]
use crate::async_operator::Next;
pub type BoxOperator<'a, I, O> = Box<dyn Operator<I, Output = O> + Send + 'a>;
pub type LocalBoxOperator<'a, I, O> = Box<dyn Operator<I, Output = O> + 'a>;
pub trait Operator<I> {
type Output;
fn next(&mut self, input: I) -> Self::Output;
}
pub trait OperatorExt<I>: Operator<I> {
fn then<P2>(self, other: P2) -> Then<I, Self, P2>
where
Self: Sized,
P2: Operator<Self::Output>,
{
Then(self, other, core::marker::PhantomData::default())
}
fn facet<P2>(self, other: P2) -> Facet<I, Self, P2>
where
Self: Sized,
P2: Operator<I>,
{
facet(self, other)
}
fn map<O, F>(self, f: F) -> Then<I, Self, Map<F>>
where
Self: Sized,
F: FnMut(Self::Output) -> O,
{
self.then(map(f))
}
fn boxed<'a>(self) -> BoxOperator<'a, I, Self::Output>
where
Self: Sized + Send + 'a,
{
Box::new(self)
}
fn boxed_local<'a>(self) -> LocalBoxOperator<'a, I, Self::Output>
where
Self: Sized + 'a,
{
Box::new(self)
}
#[cfg(feature = "async")]
fn into_async_operator(self) -> Next<Self>
where
Self: Sized,
{
Next { inner: self }
}
}
impl<I, T: Operator<I>> OperatorExt<I> for T {}
impl<I, P> Operator<I> for Box<P>
where
P: Operator<I> + ?Sized,
{
type Output = P::Output;
fn next(&mut self, input: I) -> Self::Output {
self.as_mut().next(input)
}
}