flatty_base/
error.rs

1/// Flat type operation error.
2#[derive(Clone, Debug, PartialEq, Eq)]
3pub struct Error {
4    pub kind: ErrorKind,
5    /// An offset from the beginning of flat type memory where error occur.
6    pub pos: usize,
7}
8
9/// Error kinds that can occur while working with flat types.
10#[derive(Clone, Debug, PartialEq, Eq)]
11pub enum ErrorKind {
12    /// The byte slice has insufficient size to be interpreted as required type.
13    InsufficientSize,
14    /// Memory isn't properly aligned to be interpreted as required type.
15    BadAlign,
16    /// Enum binary representation contains index that doesn't match any of possible enum states.
17    InvalidEnumTag,
18    /// Invalid binary representation of the type.
19    InvalidData,
20    /// Any other error.
21    Other,
22}
23
24impl Error {
25    /// Clone `self` and add `offset` to [`Self::pos`].
26    pub fn offset(mut self, offset: usize) -> Self {
27        self.pos += offset;
28        self
29    }
30}