netlink_packet_utils/
errors.rs

1// SPDX-License-Identifier: MIT
2
3use anyhow::anyhow;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
7#[error("Encode error occurred: {inner}")]
8pub struct EncodeError {
9    inner: anyhow::Error,
10}
11
12impl From<&'static str> for EncodeError {
13    fn from(msg: &'static str) -> Self {
14        EncodeError {
15            inner: anyhow!(msg),
16        }
17    }
18}
19
20impl From<String> for EncodeError {
21    fn from(msg: String) -> Self {
22        EncodeError {
23            inner: anyhow!(msg),
24        }
25    }
26}
27
28impl From<anyhow::Error> for EncodeError {
29    fn from(inner: anyhow::Error) -> EncodeError {
30        EncodeError { inner }
31    }
32}
33
34#[derive(Debug, Error)]
35#[error("Decode error occurred: {inner}")]
36pub struct DecodeError {
37    inner: anyhow::Error,
38}
39
40impl From<&'static str> for DecodeError {
41    fn from(msg: &'static str) -> Self {
42        DecodeError {
43            inner: anyhow!(msg),
44        }
45    }
46}
47
48impl From<String> for DecodeError {
49    fn from(msg: String) -> Self {
50        DecodeError {
51            inner: anyhow!(msg),
52        }
53    }
54}
55
56impl From<anyhow::Error> for DecodeError {
57    fn from(inner: anyhow::Error) -> DecodeError {
58        DecodeError { inner }
59    }
60}