compio_actor\mailbox/
error.rs1use std::{error::Error, fmt};
2
3use super::Call;
4use crate::Message;
5
6#[derive(Debug, PartialEq, Eq)]
8pub enum DeliverError<M: Message> {
9 Full(M),
11 Closed(M),
13}
14
15impl<M: Message> DeliverError<M> {
16 pub fn into_inner(self) -> M {
18 match self {
19 Self::Full(message) | Self::Closed(message) => message,
20 }
21 }
22}
23
24impl<M: Message> fmt::Display for DeliverError<M> {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 Self::Full(_) => f.write_str("actor mailbox is full"),
28 Self::Closed(_) => f.write_str("actor mailbox is closed"),
29 }
30 }
31}
32
33impl<M: Message + fmt::Debug> Error for DeliverError<M> {}
34
35#[derive(Debug, PartialEq, Eq)]
37pub enum CallError<M: Message> {
38 Full(M),
40 Closed(M),
42 NoReply,
44}
45
46impl<M: Message> CallError<M> {
47 pub(super) fn from_deliver<R: Message>(error: DeliverError<Call<M, R>>) -> Self {
48 match error {
49 DeliverError::Full(call) => Self::Full(call.into_message()),
50 DeliverError::Closed(call) => Self::Closed(call.into_message()),
51 }
52 }
53
54 pub fn into_inner(self) -> Option<M> {
56 match self {
57 Self::Full(message) | Self::Closed(message) => Some(message),
58 Self::NoReply => None,
59 }
60 }
61}
62
63impl<M: Message> fmt::Display for CallError<M> {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 match self {
66 Self::Full(_) => f.write_str("actor mailbox is full"),
67 Self::Closed(_) => f.write_str("actor mailbox is closed"),
68 Self::NoReply => f.write_str("actor did not reply"),
69 }
70 }
71}
72
73impl<M: Message + fmt::Debug> Error for CallError<M> {}