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, string::FromUtf8Error,
6};
7use yaml_serde::Error as SerdeYamlError;
8
9#[derive(Debug, Clone, PartialEq)]
12pub struct Alert {
13 val: String,
14}
15
16impl From<ParseError> for Alert {
17 fn from(value: ParseError) -> Self {
19 Alert {
20 val: format!("chrono::ParseError: {}", value),
21 }
22 }
23}
24
25impl From<RegexError> for Alert {
26 fn from(value: RegexError) -> Self {
28 Alert {
29 val: format!("regex::Error: {}", value),
30 }
31 }
32}
33
34impl From<IOError> for Alert {
35 fn from(value: IOError) -> Self {
37 Alert {
38 val: format!("io::Error: {}", value),
39 }
40 }
41}
42
43impl From<ParseIntError> for Alert {
44 fn from(value: ParseIntError) -> Self {
46 Alert {
47 val: format!("num::ParseIntError: {}", value),
48 }
49 }
50}
51
52impl From<SerdeJsonError> for Alert {
53 fn from(value: SerdeJsonError) -> Self {
55 Alert {
56 val: format!("serde_json::Error: {}", value),
57 }
58 }
59}
60
61impl From<SerdeYamlError> for Alert {
62 fn from(value: SerdeYamlError) -> Self {
64 Alert {
65 val: format!("yaml_serde::Error: {}", value),
66 }
67 }
68}
69
70impl From<FromUtf8Error> for Alert {
71 fn from(value: FromUtf8Error) -> Self {
73 Alert {
74 val: format!("string::FromUtf8Error: {}", value),
75 }
76 }
77}
78
79impl From<&str> for Alert {
80 fn from(value: &str) -> Self {
82 Alert {
83 val: String::from(value),
84 }
85 }
86}
87
88impl From<String> for Alert {
89 fn from(value: String) -> Self {
91 Alert { val: value }
92 }
93}
94
95impl From<&String> for Alert {
96 fn from(value: &String) -> Self {
98 Alert { val: value.clone() }
99 }
100}
101
102impl Display for Alert {
103 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
104 writeln!(f, "{}", self.val)
105 }
106}