Skip to main content

polybox_core/
errors.rs

1use crate::RxError;
2use thiserror::Error;
3
4/// Error returned when sending a message, checking at compile-time that
5/// the message is actually accepted by the actor.
6#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq, Hash)]
7pub enum SendCheckedError<M> {
8    Closed(M),
9    NotAccepted(M),
10}
11
12/// The channel has been closed, and no longer accepts new messages.
13#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
14pub struct SendError<M>(pub M);
15
16/// Error returned when sending a request.
17///
18/// This error combines failures in sending and receiving.
19#[derive(Debug, thiserror::Error, Clone, Copy, PartialEq, Eq)]
20pub enum RequestError<M> {
21    NoReply,
22    Closed(M),
23}
24
25impl<T> From<SendError<T>> for SendCheckedError<T> {
26    fn from(err: SendError<T>) -> Self {
27        Self::Closed(err.0)
28    }
29}
30
31impl<T> From<RxError> for RequestError<T> {
32    fn from(RxError: RxError) -> Self {
33        Self::NoReply
34    }
35}
36
37impl<T> From<SendError<T>> for RequestError<T> {
38    fn from(err: SendError<T>) -> Self {
39        Self::Closed(err.0)
40    }
41}