1use crate::packet::TpduSize;
2use num_enum::TryFromPrimitiveError;
3use std::io;
4use thiserror::Error;
5use tpkt::ToTpktError;
6
7#[derive(Debug, Error)]
8pub enum Error {
9 #[error(transparent)]
10 IoErr(#[from] io::Error),
11
12 #[error("Error: {0}")]
13 Error(String),
14}
15
16pub type Result<T> = std::result::Result<T, Error>;
17
18pub trait ToCoptError {
19 fn to_err(self) -> Error;
20}
21
22impl<T: ToCoptError> From<T> for Error {
23 fn from(value: T) -> Self {
24 value.to_err()
25 }
26}
27
28impl ToTpktError for Error {
29 fn to_err(self) -> tpkt::Error {
30 tpkt::Error::Error(self.to_string())
31 }
32}
33
34impl From<TryFromPrimitiveError<TpduSize>> for Error {
35 fn from(value: TryFromPrimitiveError<TpduSize>) -> Self {
36 Self::Error(value.to_string())
37 }
38}