completeq_rs/result.rs
1use crate::{error::CompleteQError, user_event::UserEvent};
2
3/// Send complete event result status.
4pub enum EmitResult {
5 /// Fire completed event success
6 Completed,
7
8 /// No surviving receivers, channel closed.
9 Closed,
10}
11
12impl EmitResult {
13 /// Convert `EmitResult` structure into [`Result<(),CompleteQError>`]
14 ///
15 /// If channel closed this method will return [`Err(CompleteQError::PipeBroken)`]
16 pub fn completed(self) -> Result<(), CompleteQError> {
17 match self {
18 Self::Completed => Ok(()),
19 Self::Closed => Err(CompleteQError::PipeBroken),
20 }
21 }
22
23 /// Helper method to detect if `EmitResult` enum is [`EmitResult::Closed`]
24 pub fn is_closed(&self) -> bool {
25 match self {
26 Self::Completed => false,
27 Self::Closed => true,
28 }
29 }
30}
31
32/// Receiver poll return value.
33pub enum ReceiveResult<E: UserEvent> {
34 /// Success received one event message
35 Success(Option<E::Argument>),
36 /// Receive event message timeout
37 Timeout,
38}
39
40impl<E: UserEvent> ReceiveResult<E> {
41 /// Convert `ReceiveResult` structure into [`Result<(),CompleteQError>`]
42 ///
43 /// If timeout this method will return [`Err(CompleteQError::Timeout)`]
44 pub fn success(self) -> Result<Option<E::Argument>, CompleteQError> {
45 match self {
46 Self::Success(argument) => Ok(argument),
47 Self::Timeout => Err(CompleteQError::Timeout),
48 }
49 }
50
51 /// Helper method to detect if `ReceiveResult` enum is [`ReceiveResult::Timeout`]
52 pub fn is_timeout(&self) -> bool {
53 match self {
54 Self::Timeout => true,
55 _ => false,
56 }
57 }
58}
59
60pub(crate) enum EmitInnerResult<E: UserEvent> {
61 /// Fire completed event success
62 Completed,
63 /// Sending quene pending, return unsuccessful delivery message
64 Pending(E::Argument),
65
66 /// No surviving receivers, channel closed.
67 Closed,
68}