Skip to main content

ipc_channel/
error.rs

1use std::fmt::Display;
2use std::io;
3
4use thiserror::Error;
5
6#[derive(Debug, Error)]
7/// An error that occurs for serialization or deserialization
8pub struct SerDeError(#[from] pub(crate) postcard::Error);
9
10impl Display for SerDeError {
11    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12        write!(f, "Serialization/Deserialization error")
13    }
14}
15
16#[derive(Debug, Error)]
17pub enum IpcError {
18    #[error("Error in decoding or encoding: {0}.")]
19    SerializationError(#[from] SerDeError),
20    #[error("Error in IO: {0}.")]
21    Io(#[from] io::Error),
22    /// Disconnected is returned when receiving from a channel if
23    /// all senders for the channel have been dropped and no messages
24    /// remain to be received.
25    #[error("Ipc Disconnected.")]
26    Disconnected,
27}
28
29#[derive(Debug, Error)]
30pub enum TryRecvError {
31    #[error("IPC error {0}.")]
32    IpcError(#[from] IpcError),
33    #[error("Channel empty.")]
34    Empty,
35}
36
37/// TrySelectError is returned by non-blocking variants of IpcReceiverSet::select.
38#[derive(Debug, Error)]
39pub enum TrySelectError {
40    #[error("Error in IO: {0}.")]
41    IoError(#[from] io::Error),
42    #[error("No messages were received and no disconnections occurred.")]
43    Empty,
44}