semver_common/models/
alert.rs1use chrono::ParseError;
2use regex::Error as RegexError;
3use serde_json::Error as SerdeJsonError;
4use std::{
5 convert::From, fmt::Display, io::Error as IOError, num::ParseIntError, str::ParseBoolError,
6 string::FromUtf8Error,
7};
8use yaml_serde::Error as SerdeYamlError;
9
10#[derive(Debug, Clone, PartialEq)]
13pub struct Alert {
14 val: String,
15}
16
17impl From<ParseError> for Alert {
18 fn from(value: ParseError) -> Self {
20 Alert {
21 val: format!("chrono::ParseError: {}", value),
22 }
23 }
24}
25
26impl From<ParseBoolError> for Alert {
27 fn from(value: ParseBoolError) -> Self {
29 Alert {
30 val: format!("str::ParseBoolError: {}", value),
31 }
32 }
33}
34
35impl From<RegexError> for Alert {
36 fn from(value: RegexError) -> Self {
38 Alert {
39 val: format!("regex::Error: {}", value),
40 }
41 }
42}
43
44impl From<IOError> for Alert {
45 fn from(value: IOError) -> Self {
47 Alert {
48 val: format!("io::Error: {}", value),
49 }
50 }
51}
52
53impl From<ParseIntError> for Alert {
54 fn from(value: ParseIntError) -> Self {
56 Alert {
57 val: format!("num::ParseIntError: {}", value),
58 }
59 }
60}
61
62impl From<SerdeJsonError> for Alert {
63 fn from(value: SerdeJsonError) -> Self {
65 Alert {
66 val: format!("serde_json::Error: {}", value),
67 }
68 }
69}
70
71impl From<SerdeYamlError> for Alert {
72 fn from(value: SerdeYamlError) -> Self {
74 Alert {
75 val: format!("yaml_serde::Error: {}", value),
76 }
77 }
78}
79
80impl From<FromUtf8Error> for Alert {
81 fn from(value: FromUtf8Error) -> Self {
83 Alert {
84 val: format!("string::FromUtf8Error: {}", value),
85 }
86 }
87}
88
89impl From<&str> for Alert {
90 fn from(value: &str) -> Self {
92 Alert {
93 val: String::from(value),
94 }
95 }
96}
97
98impl From<String> for Alert {
99 fn from(value: String) -> Self {
101 Alert { val: value }
102 }
103}
104
105impl From<&String> for Alert {
106 fn from(value: &String) -> Self {
108 Alert { val: value.clone() }
109 }
110}
111
112impl Display for Alert {
113 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
114 writeln!(f, "{}", self.val)
115 }
116}