Skip to content

Commit

Permalink
anyhow (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncolburne authored Mar 15, 2023
1 parent d0d1dd6 commit 89cd0cc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ keywords = ["cesr", "keri", "acdc"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "~1"
argon2 = "~0.5"
base64 = "~0.21"
blake2 = "~0.10"
Expand Down
16 changes: 8 additions & 8 deletions src/core/indexer/tables.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::error::{Error, Result};
use crate::error::{err, Error, Result};
/// Codex is codex hard (stable) part of all indexer derivation codes.
///
/// Codes indicate which list of keys, current and/or prior next, index is for:
Expand Down Expand Up @@ -131,27 +131,27 @@ pub(crate) fn sizage(s: &str) -> Result<Sizage> {
"0z" => Sizage { hs: 2, ss: 2, os: 0, fs: u32::MAX, ls: 0 },
"1z" => Sizage { hs: 2, ss: 2, os: 1, fs: 76, ls: 1 },
"4z" => Sizage { hs: 2, ss: 6, os: 3, fs: 80, ls: 1 },
_ => return Err(Box::new(Error::UnknownSizage(s.to_string()))),
_ => return err!(Error::UnknownSizage(s.to_string())),
})
}

pub(crate) fn hardage(c: char) -> Result<u32> {
match c {
'A'..='Z' | 'a'..='z' => Ok(1),
'0'..='4' => Ok(2),
'-' => Err(Box::new(Error::UnexpectedCode("count code start".to_owned()))),
'_' => Err(Box::new(Error::UnexpectedCode("op code start".to_owned()))),
_ => Err(Box::new(Error::UnknownHardage(c.to_string()))),
'-' => err!(Error::UnexpectedCode("count code start".to_owned())),
'_' => err!(Error::UnexpectedCode("op code start".to_owned())),
_ => err!(Error::UnknownHardage(c.to_string())),
}
}

pub(crate) fn bardage(b: u8) -> Result<u32> {
match b {
b'\x00'..=b'\x33' => Ok(1),
b'\x34'..=b'\x38' => Ok(2),
b'\x3e' => Err(Box::new(Error::UnexpectedCode("count code start".to_owned()))),
b'\x3f' => Err(Box::new(Error::UnexpectedCode("op code start".to_owned()))),
_ => Err(Box::new(Error::UnknownBardage(b.to_string()))),
b'\x3e' => err!(Error::UnexpectedCode("count code start".to_owned())),
b'\x3f' => err!(Error::UnexpectedCode("op code start".to_owned())),
_ => err!(Error::UnknownBardage(b.to_string())),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/tholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ impl Tholder {
}

pub fn satisfy(&self, indices: &[u32]) -> Result<bool> {
return if self.number().is_some() {
if self.number().is_some() {
self.satisfy_numeric(indices)
} else if self.bexter().is_some() {
self.satisfy_weighted(indices)
} else {
Ok(false)
};
}
}

fn satisfy_numeric(&self, indices: &[u32]) -> Result<bool> {
Expand Down
14 changes: 7 additions & 7 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::ops::{Index, IndexMut};
use indexmap::IndexMap;
use serde_json::{json, Value as JsonValue};

use crate::error::{err, BoxedError, Error as CESRError, Result};
use crate::error::{err, Error as CESRError, Result};

pub type Array = Vec<Value>;
pub type Object = IndexMap<String, Value>;
Expand Down Expand Up @@ -310,7 +310,7 @@ impl From<&JsonValue> for Value {
}

impl TryFrom<&Value> for String {
type Error = BoxedError;
type Error = anyhow::Error;

fn try_from(v: &Value) -> Result<Self> {
match v {
Expand All @@ -321,7 +321,7 @@ impl TryFrom<&Value> for String {
}

impl TryFrom<&Value> for bool {
type Error = BoxedError;
type Error = anyhow::Error;

fn try_from(v: &Value) -> Result<Self> {
match v {
Expand All @@ -332,7 +332,7 @@ impl TryFrom<&Value> for bool {
}

impl TryFrom<&Value> for i64 {
type Error = BoxedError;
type Error = anyhow::Error;

fn try_from(v: &Value) -> Result<Self> {
match v {
Expand All @@ -349,7 +349,7 @@ impl TryFrom<&Value> for i64 {
}

impl TryFrom<&Value> for f64 {
type Error = BoxedError;
type Error = anyhow::Error;

fn try_from(v: &Value) -> Result<Self> {
match v {
Expand All @@ -366,7 +366,7 @@ impl TryFrom<&Value> for f64 {
}

impl TryFrom<&Value> for Vec<Value> {
type Error = BoxedError;
type Error = anyhow::Error;

fn try_from(v: &Value) -> Result<Self> {
match v {
Expand All @@ -377,7 +377,7 @@ impl TryFrom<&Value> for Vec<Value> {
}

impl TryFrom<&Value> for IndexMap<String, Value> {
type Error = BoxedError;
type Error = anyhow::Error;

fn try_from(v: &Value) -> Result<Self> {
match v {
Expand Down
5 changes: 2 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub type BoxedError = Box<dyn std::error::Error>;
pub type Result<T> = core::result::Result<T, BoxedError>;
pub type Result<T> = anyhow::Result<T>;

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -71,7 +70,7 @@ pub enum Error {

macro_rules! err {
($e:expr) => {
Err(Box::new($e))
Err($e.into())
};
}

Expand Down

0 comments on commit 89cd0cc

Please sign in to comment.