Skip to content

Commit

Permalink
Merge pull request #19 from fluiderson/thiserror
Browse files Browse the repository at this point in the history
feat: add an `Error` implementation for an error type
  • Loading branch information
Slesarew authored May 29, 2024
2 parents 56fc336 + cf95774 commit ac8b4f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bitvec = { version = "1.0.1", default-features = false, features = ["alloc"] }
sha2 = { version = "0.10.6", default-features = false }

bitvec = {version = "1.0.1", default-features = false, features = ["alloc"]}
sha2 = {version = "0.10.6", default-features = false}
thiserror = { version = "1", optional = true }

[dev-dependencies]
hex = "0.4.3"

[features]
default = ["std", "sufficient-memory"]
std = []
std = ["thiserror"]
sufficient-memory = []

[lib]
Expand Down
14 changes: 14 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#[cfg(feature = "std")]
use std::fmt::{Debug, Display, Formatter, Result};
#[cfg(feature = "std")]
use thiserror::Error;

#[derive(Debug)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum ErrorWordList {
DamagedWord,
InvalidChecksum,
Expand All @@ -7,3 +13,11 @@ pub enum ErrorWordList {
NoWord,
WordsNumber,
}

// TODO: provide actual error descriptions.
#[cfg(feature = "std")]
impl Display for ErrorWordList {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
<Self as Debug>::fmt(self, f)
}
}

0 comments on commit ac8b4f0

Please sign in to comment.