soft_ascii_string/
error.rs1use std::fmt::{self, Debug};
2use std::error::Error;
3
4#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
6pub struct StringFromStrError;
7impl Error for StringFromStrError {
8 fn description(&self) -> &str {
9 "&str does contain non us-ascii chars and can not be converted to a SoftAsciiString"
10 }
11}
12
13impl fmt::Display for StringFromStrError {
14 fn fmt(&self, fter: &mut fmt::Formatter) -> fmt::Result {
15 write!(fter, "{}", self.description())
16 }
17}
18
19#[derive(Debug, PartialEq, Eq, Clone, Hash)]
21pub struct FromSourceError<S: Debug> {
22 source: S
23}
24
25impl<S> FromSourceError<S>
26 where S: Debug
27{
28
29 pub fn new(source: S) -> Self {
31 FromSourceError { source }
32 }
33
34 pub fn source(&self) -> &S {
39 &self.source
40 }
41
42
43 pub fn into_source(self) -> S {
50 self.source
51 }
52}
53
54
55
56impl<S> Error for FromSourceError<S>
57 where S: Debug
58{
59 fn description(&self) -> &str {
60 concat!("could not create a SoftAscii representation of the source",
61 "as the source contained non us-ascii chars")
62 }
63}
64
65impl<S> fmt::Display for FromSourceError<S>
66 where S: Debug
67{
68 fn fmt(&self, fter: &mut fmt::Formatter) -> fmt::Result {
69 write!(fter, "source contains non us-ascii chars: {:?}", self.source)
70 }
71}