Skip to main content

ploys/changelog/
error.rs

1use std::convert::Infallible;
2use std::fmt::{self, Display};
3
4/// The changelog error.
5#[derive(Debug)]
6pub enum Error {
7    /// A UTF-8 error.
8    Utf8(std::str::Utf8Error),
9}
10
11impl Display for Error {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        match self {
14            Self::Utf8(err) => Display::fmt(err, f),
15        }
16    }
17}
18
19impl std::error::Error for Error {
20    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
21        match self {
22            Self::Utf8(err) => Some(err),
23        }
24    }
25}
26
27impl From<Infallible> for Error {
28    fn from(err: Infallible) -> Self {
29        match err {}
30    }
31}
32
33impl From<std::str::Utf8Error> for Error {
34    fn from(err: std::str::Utf8Error) -> Self {
35        Self::Utf8(err)
36    }
37}