cargo_toml_builder/
error.rs1use std::{
2 fmt,
3 error::Error as StdError,
4};
5
6#[derive(Debug, Clone, PartialEq)]
8pub struct Error {
9 inner: ErrorKind,
10}
11
12impl fmt::Display for Error {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 fmt::Display::fmt(&self.inner, f)
15 }
16}
17
18impl StdError for Error {
19 fn description(&self) -> &str {
20 StdError::description(&self.inner)
21 }
22}
23
24impl From<String> for Error {
25 fn from(s: String) -> Error {
26 Error { inner: From::from(s) }
27 }
28}
29
30impl<'a> From<&'a str> for Error {
31 fn from(s: &'a str) -> Error {
32 Error { inner: From::from(s) }
33 }
34}
35
36#[derive(Debug, Clone, PartialEq)]
37enum ErrorKind {
38 Custom(String),
39}
40
41impl fmt::Display for ErrorKind {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 match *self {
44 ErrorKind::Custom(ref s) => f.write_str(s),
45 }
46 }
47}
48
49impl StdError for ErrorKind {
50 fn description(&self) -> &str {
51 match *self {
52 ErrorKind::Custom(ref s) => s,
53 }
54 }
55}
56
57impl From<String> for ErrorKind {
58 fn from(s: String) -> ErrorKind {
59 ErrorKind::Custom(s)
60 }
61}
62
63impl<'a> From<&'a str> for ErrorKind {
64 fn from(s: &'a str) -> ErrorKind {
65 ErrorKind::Custom(s.to_string())
66 }
67}
68