ratman_netmod/
result.rs

1//! Error handling types
2
3use std::error::Error as StdError;
4use std::fmt::{Display, Formatter, Result as FmtResult};
5
6/// Error return types emitted by `Endpoint` implementations
7///
8/// Underlying hardware errors are entirely shadowed, because it
9/// wouldn't reasonably be possible to encode them all and error
10/// messages are prone to confusion. Instead, a simple set of common
11/// hardware and buffer related errors was selected to be retunrable.
12///
13/// Routing layers (such as `R.A.T.M.A.N.` are expected to respond
14/// gracefully to all of these errors, so none of them should be
15/// considered fatal.
16#[derive(Debug)]
17pub enum Error {
18    /// The requested operation is not supported by an adapter
19    ///
20    /// Valid reasons to return this error might be a routing layer
21    /// trying to setup a `listen` handle on platforms that only
22    /// support basic polling.
23    ///
24    ///This error **must not** be used for dealing with a `Frame` that
25    /// exceeds available buffer capacity!
26    NotSupported,
27    /// The provided `Frame` was too large to send on this adapter
28    ///
29    /// Sometimes a routing layer (such as `R.A.T.M.A.N.`) will
30    /// partially ignore the provided `size_hint` for efficiency
31    /// reasons and provide a `Frame` to an adapter that is larger. If
32    /// a backend has an upper size limit, encoded in the `size_hint`
33    /// (or larger), and a `Frame` exceeds this limit, returning this
34    /// error is permited.
35    ///
36    /// It will result in the routing later resubmitting a smaller
37    /// `Frame` sequence.
38    FrameTooLarge,
39    /// During the most recent transmission a connection drop occured
40    ///
41    /// This error can be thrown both during `send` and `poll`, but
42    /// should not be returned by `listen`, as an invalid `Frame` can
43    /// simply be dropped.
44    ConnectionLost,
45    /// During desequencing an error occured
46    DesequenceFault,
47}
48
49impl Display for Error {
50    fn fmt(&self, f: &mut Formatter) -> FmtResult {
51        write!(f, "{:?}", self)
52    }
53}
54
55impl StdError for Error {}
56
57/// A `netmod` specific `Result` wrapper
58pub type Result<T> = std::result::Result<T, Error>;