rsdiff_core/error/kinds/
external.rs1use super::ErrorType;
6#[cfg(feature = "serde")]
7use serde::{Deserialize, Serialize};
8use strum::{Display, EnumCount, EnumIs, VariantNames};
9
10#[derive(
11 Clone,
12 Copy,
13 Debug,
14 Default,
15 Display,
16 EnumCount,
17 EnumIs,
18 Eq,
19 Hash,
20 Ord,
21 PartialEq,
22 PartialOrd,
23 VariantNames,
24)]
25#[cfg_attr(
26 feature = "serde",
27 derive(Deserialize, Serialize,),
28 serde(rename_all = "snake_case")
29)]
30#[strum(serialize_all = "snake_case")]
31pub enum ExternalError<E = String> {
32 Custom(E),
33 #[default]
34 Unknown,
35}
36
37impl<E> ExternalError<E> {
38 pub fn new(error: E) -> Self {
39 Self::Custom(error)
40 }
41
42 pub fn unknown() -> Self {
43 Self::Unknown
44 }
45}
46
47impl<E> std::error::Error for ExternalError<E> where E: std::fmt::Debug {}
48
49impl<E> ErrorType for ExternalError<E>
50where
51 E: ToString,
52{
53 type Kind = ExternalError<E>;
54
55 fn kind(&self) -> &Self::Kind {
56 self
57 }
58
59 fn name(&self) -> String {
60 match self {
61 Self::Custom(inner) => inner.to_string(),
62 _ => self.to_string(),
63 }
64 }
65}