parsenic/error/
lost.rs

1use core::fmt;
2
3/// Destination lost (from either corruption or disconnection)
4#[derive(Copy, Clone, Eq, PartialEq, Debug, Default)]
5#[non_exhaustive]
6pub struct LostError(Option<&'static str>);
7
8/// __*`unstable-error`*__: feature required
9#[cfg(feature = "unstable-error")]
10impl core::error::Error for LostError {}
11
12impl fmt::Display for LostError {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        f.write_str("destination lost")?;
15
16        if let Some(message) = self.0 {
17            f.write_str(", ")?;
18            f.write_str(message)?;
19        }
20
21        Ok(())
22    }
23}
24
25impl LostError {
26    /// Create a new [`LostError`].
27    pub fn new() -> Self {
28        Self(None)
29    }
30
31    /// Create a new [`LostError`] from message payload.
32    pub fn from_message(message: &'static str) -> Self {
33        Self(Some(message))
34    }
35
36    /// Return the message payload.
37    pub fn message(&self) -> Option<&'static str> {
38        self.0
39    }
40}