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
mod unsync_cloneable;
mod cloneable;

pub use self::cloneable::Cloneable;
pub use self::unsync_cloneable::UnsyncCloneable;


use futures::Sink;


/// An extension of `Sink` provided by `futures` crate.
/// Any `Sink` implements `SinkExt` automatically.
/// All you are needed to do is to import `SinkExt`.
///
/// ```
/// use ex_futures::SinkExt;
/// ```
pub trait SinkExt: Sink {
    fn cloneable(self) -> Cloneable<Self>
    where
        Self: Sized,
    {
        self::cloneable::cloneable(self)
    }
    /// Convert any kind of sink into "cloneable" sink but unsync.
    /// That is kind like mpsc.
    ///
    /// # Examples
    /// ```
    /// # extern crate futures;
    /// # extern crate ex_futures;
    /// use ex_futures::SinkExt;
    ///
    /// # fn main() {
    /// let (tx, rx) = ::futures::sync::mpsc::channel::<usize>(42);
    ///
    /// let cloneable_sink = tx.unsync_cloneable(); // Convert "tx" into cloneable.
    /// let cloneable_sink2 = cloneable_sink.clone(); // Now you can clone it.
    /// # }
    /// ```
    fn unsync_cloneable(self) -> UnsyncCloneable<Self>
    where
        Self: Sized,
    {
        self::unsync_cloneable::unsync_cloneable(self)
    }
}


impl<S> SinkExt for S
where
    S: Sink,
{
}