diff options
| author | pml68 <contact@pml68.me> | 2024-10-26 22:22:45 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.me> | 2024-10-26 22:22:45 +0200 |
| commit | 27fcc7a6a3dee7777449c0517a11838310aa164d (patch) | |
| tree | da813fb6d9bab57d9b114280f761a9635a1a8903 /iced_builder/src/lib.rs | |
| parent | test: remove all leftover println calls (diff) | |
| download | iced-builder-27fcc7a6a3dee7777449c0517a11838310aa164d.tar.gz | |
feat: implement `std::error::Error` for custom `Error` enum
Diffstat (limited to 'iced_builder/src/lib.rs')
| -rw-r--r-- | iced_builder/src/lib.rs | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/iced_builder/src/lib.rs b/iced_builder/src/lib.rs index 1c7af06..14a044e 100644 --- a/iced_builder/src/lib.rs +++ b/iced_builder/src/lib.rs @@ -8,41 +8,27 @@ use types::{ element_name::ElementName, project::Project, rendered_element::RenderedElement, DesignerPage, }; -#[derive(Debug, Clone)] +use thiserror::Error; + +#[derive(Debug, Clone, Error)] pub enum Error { - IOError(std::io::ErrorKind), + #[error("an IO error accured: {0}")] + IOError(String), + #[error("a Serde error accured: {0}")] SerdeError(String), + #[error("an RustFmt error accured: {0}")] FormatError(String), + #[error("the element tree contains no matching element")] NonExistentElement, + #[error("the file dialog has been closed without selecting a valid option")] DialogClosed, + #[error("{0}")] String(String), } -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::SerdeError(string) | Self::FormatError(string) | Self::String(string) => { - write!(f, "{}", string) - } - Self::IOError(kind) => { - write!(f, "{}", kind) - } - Self::NonExistentElement => { - write!(f, "The element tree contains no matching element.") - } - Self::DialogClosed => { - write!( - f, - "The file dialog has been closed without selecting a valid option." - ) - } - } - } -} - impl From<std::io::Error> for Error { fn from(value: std::io::Error) -> Self { - Self::IOError(value.kind()) + Self::IOError(value.to_string()) } } |
