Skip to content

Commit a2e3459

Browse files
Remove anyhow (#46)
Resolves #27. Not only should anyhow generally not be used in libraries, it adds no value here (it arguably makes error handling from this library worse actually). Bumps version to 2.0 as this is a breaking API change :/ Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com>
1 parent 2175c62 commit a2e3459

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tiny-bip39"
3-
version = "1.0.1"
3+
version = "2.0.0"
44
authors = [
55
"Stephen Oliver <steve@infincia.com>",
66
"Maciej Hirsz <hello@maciej.codes>",
@@ -32,7 +32,6 @@ default-langs = ["chinese-simplified", "chinese-traditional", "french", "italian
3232
default = ["default-langs", "rand"]
3333

3434
[dependencies]
35-
anyhow = "1.0.57"
3635
thiserror = "1.0.31"
3736
rustc-hash = "1.1.0"
3837
sha2 = "0.10.2"

src/mnemonic.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::error::ErrorKind;
55
use crate::language::Language;
66
use crate::mnemonic_type::MnemonicType;
77
use crate::util::{checksum, BitWriter, IterExt};
8-
use anyhow::Error;
98
use std::fmt;
109
use std::mem;
1110
use unicode_normalization::UnicodeNormalization;
@@ -85,7 +84,7 @@ impl Mnemonic {
8584
/// ```
8685
///
8786
/// [Mnemonic]: ../mnemonic/struct.Mnemonic.html
88-
pub fn from_entropy(entropy: &[u8], lang: Language) -> Result<Mnemonic, Error> {
87+
pub fn from_entropy(entropy: &[u8], lang: Language) -> Result<Mnemonic, ErrorKind> {
8988
// Validate entropy size
9089
MnemonicType::for_key_size(entropy.len() * 8)?;
9190

@@ -143,7 +142,7 @@ impl Mnemonic {
143142
/// ```
144143
///
145144
/// [Mnemonic]: ../mnemonic/struct.Mnemonic.html
146-
pub fn from_phrase(phrase: &str, lang: Language) -> Result<Mnemonic, Error> {
145+
pub fn from_phrase(phrase: &str, lang: Language) -> Result<Mnemonic, ErrorKind> {
147146
let phrase = Zeroizing::new(
148147
phrase
149148
.split_whitespace()
@@ -179,7 +178,7 @@ impl Mnemonic {
179178
///
180179
/// assert!(Mnemonic::validate(test_mnemonic, Language::English).is_ok());
181180
/// ```
182-
pub fn validate(phrase: &str, lang: Language) -> Result<(), Error> {
181+
pub fn validate(phrase: &str, lang: Language) -> Result<(), ErrorKind> {
183182
Mnemonic::phrase_to_entropy(phrase, lang)?;
184183

185184
Ok(())
@@ -190,7 +189,7 @@ impl Mnemonic {
190189
/// Only intended for internal use, as returning a `Vec<u8>` that looks a bit like it could be
191190
/// used as the seed is likely to cause problems for someone eventually. All the other functions
192191
/// that return something like that are explicit about what it is and what to use it for.
193-
fn phrase_to_entropy(phrase: &str, lang: Language) -> Result<Vec<u8>, Error> {
192+
fn phrase_to_entropy(phrase: &str, lang: Language) -> Result<Vec<u8>, ErrorKind> {
194193
let wordmap = lang.wordmap();
195194

196195
// Preallocate enough space for the longest possible word list

src/mnemonic_type.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::fmt;
2-
use anyhow::Error;
32
use crate::error::ErrorKind;
43

54
const ENTROPY_OFFSET: usize = 8;
@@ -51,7 +50,7 @@ impl MnemonicType {
5150
///
5251
/// let mnemonic_type = MnemonicType::for_word_count(12).unwrap();
5352
/// ```
54-
pub fn for_word_count(size: usize) -> Result<MnemonicType, Error> {
53+
pub fn for_word_count(size: usize) -> Result<MnemonicType, ErrorKind> {
5554
let mnemonic_type = match size {
5655
12 => MnemonicType::Words12,
5756
15 => MnemonicType::Words15,
@@ -75,7 +74,7 @@ impl MnemonicType {
7574
///
7675
/// let mnemonic_type = MnemonicType::for_key_size(128).unwrap();
7776
/// ```
78-
pub fn for_key_size(size: usize) -> Result<MnemonicType, Error> {
77+
pub fn for_key_size(size: usize) -> Result<MnemonicType, ErrorKind> {
7978
let mnemonic_type = match size {
8079
128 => MnemonicType::Words12,
8180
160 => MnemonicType::Words15,
@@ -109,7 +108,7 @@ impl MnemonicType {
109108
/// ```
110109
///
111110
/// [MnemonicType::entropy_bits()]: ./enum.MnemonicType.html#method.entropy_bits
112-
pub fn for_phrase(phrase: &str) -> Result<MnemonicType, Error> {
111+
pub fn for_phrase(phrase: &str) -> Result<MnemonicType, ErrorKind> {
113112
let word_count = phrase.split(" ").count();
114113

115114
Self::for_word_count(word_count)

0 commit comments

Comments
 (0)