smart_string/pascal_string/
error.rs1use core::fmt;
2use core::str::Utf8Error;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum TryFromStrError {
7 TooLong,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum TryFromBytesError {
14 TooLong,
16 Utf8Error(Utf8Error),
18}
19
20impl From<Utf8Error> for TryFromBytesError {
21 fn from(e: Utf8Error) -> Self {
22 TryFromBytesError::Utf8Error(e)
23 }
24}
25
26impl From<TryFromStrError> for TryFromBytesError {
27 fn from(e: TryFromStrError) -> Self {
28 match e {
29 TryFromStrError::TooLong => TryFromBytesError::TooLong,
30 }
31 }
32}
33
34impl fmt::Display for TryFromStrError {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 match self {
37 TryFromStrError::TooLong => f.write_str("string too long"),
38 }
39 }
40}
41
42impl fmt::Display for TryFromBytesError {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 match self {
45 TryFromBytesError::TooLong => f.write_str("string too long"),
46 TryFromBytesError::Utf8Error(e) => e.fmt(f),
47 }
48 }
49}