1use core::fmt;
2
3#[derive(Copy, Clone, Eq, PartialEq, Debug, Default)]
5#[non_exhaustive]
6pub struct LostError(Option<&'static str>);
7
8#[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 pub fn new() -> Self {
28 Self(None)
29 }
30
31 pub fn from_message(message: &'static str) -> Self {
33 Self(Some(message))
34 }
35
36 pub fn message(&self) -> Option<&'static str> {
38 self.0
39 }
40}