1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#![doc = "Shared protocol error types for MSRT."]
/// Broad error category for MSRT protocol failures.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ErrorKind {
/// The input was malformed.
Malformed,
/// The provided buffer was too small.
BufferTooSmall,
/// A packet boundary or integrity check failed.
Packet,
/// A reliability invariant failed.
Reliability,
/// A channel invariant failed.
Channel,
/// A protocol engine invariant failed.
Engine,
/// The requested operation is unsupported by this implementation.
Unsupported,
}
/// Shared MSRT protocol error.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Error {
kind: ErrorKind,
}
impl Error {
/// Creates a new protocol error from an error kind.
#[must_use]
pub const fn new(kind: ErrorKind) -> Self {
Self { kind }
}
/// Returns the broad error category.
#[must_use]
pub const fn kind(self) -> ErrorKind {
self.kind
}
/// Returns a malformed-input error.
#[must_use]
pub const fn malformed() -> Self {
Self::new(ErrorKind::Malformed)
}
/// Returns a buffer-too-small error.
#[must_use]
pub const fn buffer_too_small() -> Self {
Self::new(ErrorKind::BufferTooSmall)
}
/// Returns an unsupported-operation error.
#[must_use]
pub const fn unsupported() -> Self {
Self::new(ErrorKind::Unsupported)
}
}
/// Shared result type for MSRT protocol crates.
pub type Result<T> = core::result::Result<T, Error>;