summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpml68 <contact@pml68.me>2024-10-26 22:22:45 +0200
committerpml68 <contact@pml68.me>2024-10-26 22:22:45 +0200
commit27fcc7a6a3dee7777449c0517a11838310aa164d (patch)
treeda813fb6d9bab57d9b114280f761a9635a1a8903
parenttest: remove all leftover println calls (diff)
downloadiced-builder-27fcc7a6a3dee7777449c0517a11838310aa164d.tar.gz
feat: implement `std::error::Error` for custom `Error` enum
-rw-r--r--Cargo.lock9
-rw-r--r--iced_builder/Cargo.toml1
-rw-r--r--iced_builder/src/lib.rs36
-rw-r--r--iced_drop/README.md2
4 files changed, 17 insertions, 31 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d65a742..867bd8b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1593,6 +1593,7 @@ dependencies = [
"rust-format",
"serde",
"serde_json",
+ "thiserror",
"tokio",
"unique_id",
]
@@ -3563,18 +3564,18 @@ dependencies = [
[[package]]
name = "thiserror"
-version = "1.0.64"
+version = "1.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
+checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.64"
+version = "1.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
+checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602"
dependencies = [
"proc-macro2",
"quote",
diff --git a/iced_builder/Cargo.toml b/iced_builder/Cargo.toml
index d788bc2..d08d485 100644
--- a/iced_builder/Cargo.toml
+++ b/iced_builder/Cargo.toml
@@ -19,6 +19,7 @@ rfd = "0.15.0"
rust-format = "0.3.4"
unique_id = "0.1.5"
indexmap = { version = "2.6.0", features = ["serde"] }
+thiserror = "1.0.65"
[[bin]]
name = "iced-builder"
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())
}
}
diff --git a/iced_drop/README.md b/iced_drop/README.md
index 3768d54..41b637b 100644
--- a/iced_drop/README.md
+++ b/iced_drop/README.md
@@ -1,7 +1,5 @@
# iced_drop
-# Modified to use iced 0.13.1 for compatibility
-
A small library which provides a custom widget and operation to make drag and drop easier to implement in [iced](https://github.com/iced-rs/iced/tree/master)
## Usage