1#![no_std]
2#![deny(warnings)]
3extern crate futures;
5
6pub use start_send_error_sink::StartSendErrSink;
7pub use poll_complete_error_sink::PollCompleteErrSink;
8pub use close_error_sink::CloseErrSink;
9
10pub mod start_send_error_sink {
11 use futures::{Async, Poll, Sink, StartSend};
12 use core::marker::PhantomData;
13
14 #[derive(Debug, PartialEq)]
15 pub struct Error<I>(pub I);
16
17 #[derive(Debug, Default)]
20 pub struct StartSendErrSink<I> {
21 phantom_i: PhantomData<I>,
22 }
23
24 impl<I> Sink for StartSendErrSink<I> {
25 type SinkItem = I;
26 type SinkError = Error<I>;
27
28 fn start_send(
29 &mut self,
30 item: Self::SinkItem,
31 ) -> StartSend<Self::SinkItem, Self::SinkError> {
32 Err(Error(item))
33 }
34
35 fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
36 panic!("poll_complete is allowed to panic if start_send failed")
37 }
38
39 fn close(&mut self) -> Poll<(), Self::SinkError> {
40 Ok(Async::Ready(()))
41 }
42 }
43}
44
45pub mod poll_complete_error_sink {
46 use futures::{Async, AsyncSink, Poll, Sink, StartSend};
47 use core::marker::PhantomData;
48
49 #[derive(Debug, PartialEq)]
50 pub struct Error();
51
52 #[derive(Debug, Default)]
54 pub struct PollCompleteErrSink<I> {
55 phantom_i: PhantomData<I>,
56 }
57
58 impl<I> Sink for PollCompleteErrSink<I> {
59 type SinkItem = I;
60 type SinkError = Error;
61
62 fn start_send(
63 &mut self,
64 _item: Self::SinkItem,
65 ) -> StartSend<Self::SinkItem, Self::SinkError> {
66 Ok(AsyncSink::Ready)
67 }
68
69 fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
70 Err(Error())
71 }
72
73 fn close(&mut self) -> Poll<(), Self::SinkError> {
74 Ok(Async::Ready(()))
75 }
76 }
77}
78
79pub mod close_error_sink {
80 use futures::{Async, AsyncSink, Poll, Sink, StartSend};
81 use core::marker::PhantomData;
82
83 #[derive(Debug, PartialEq)]
84 pub struct Error();
85
86 #[derive(Debug, Default)]
88 pub struct CloseErrSink<I> {
89 phantom_i: PhantomData<I>,
90 }
91
92 impl<I> Sink for CloseErrSink<I> {
93 type SinkItem = I;
94 type SinkError = Error;
95
96 fn start_send(
97 &mut self,
98 _item: Self::SinkItem,
99 ) -> StartSend<Self::SinkItem, Self::SinkError> {
100 Ok(AsyncSink::Ready)
101 }
102
103 fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
104 Ok(Async::Ready(()))
105 }
106
107 fn close(&mut self) -> Poll<(), Self::SinkError> {
108 Err(Error())
109 }
110 }
111}