semver_common/models/
alert.rs1use chrono::ParseError;
2use regex::Error as RegexError;
3use serde_json::Error as SerdeError;
4use std::{
5 convert::From, fmt::Display, io::Error as IOError, num::ParseIntError, string::FromUtf8Error,
6};
7
8#[derive(Debug, Clone)]
11pub struct Alert {
12 val: String,
13}
14
15impl From<ParseError> for Alert {
16 fn from(value: ParseError) -> Self {
18 Alert {
19 val: format!("chrono::ParseError: {}", value),
20 }
21 }
22}
23
24impl From<RegexError> for Alert {
25 fn from(value: RegexError) -> Self {
27 Alert {
28 val: format!("regex::Error: {}", value),
29 }
30 }
31}
32
33impl From<IOError> for Alert {
34 fn from(value: IOError) -> Self {
36 Alert {
37 val: format!("io::Error: {}", value),
38 }
39 }
40}
41
42impl From<ParseIntError> for Alert {
43 fn from(value: ParseIntError) -> Self {
45 Alert {
46 val: format!("num::ParseIntError: {}", value),
47 }
48 }
49}
50
51impl From<SerdeError> for Alert {
52 fn from(value: SerdeError) -> Self {
54 Alert {
55 val: format!("serde_json::Error: {}", value),
56 }
57 }
58}
59
60impl From<FromUtf8Error> for Alert {
61 fn from(value: FromUtf8Error) -> Self {
63 Alert {
64 val: format!("string::FromUtf8Error: {}", value),
65 }
66 }
67}
68
69impl From<&str> for Alert {
70 fn from(value: &str) -> Self {
72 Alert {
73 val: String::from(value),
74 }
75 }
76}
77
78impl From<String> for Alert {
79 fn from(value: String) -> Self {
81 Alert { val: value }
82 }
83}
84
85impl From<&String> for Alert {
86 fn from(value: &String) -> Self {
88 Alert { val: value.clone() }
89 }
90}
91
92impl Display for Alert {
93 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
94 writeln!(f, "{}", self.val)
95 }
96}