Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

updates to core #222

Merged
merged 5 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ursa_core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cargo.lock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared objects are a murky area. I do think that given that Ursa is a primarily going to be used as an rlib, this is the right call.

11 changes: 10 additions & 1 deletion ursa_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
[package]
authors = ["The Hyperledger Ursa Contributors"]
description = "Core functionality shared across all ursa components"
edition = "2018"
documentation = "https://docs.rs/ursa_core"
edition = "2021"
license = "Apache-2.0"
name = "ursa_core"
readme = "../README.md"
version = "0.5.0"

[dependencies]
anyhow = "1.0"
core2 = "0.4"
serde = "1.0"
serde_bare = "0.5"
serde_cbor = "0.11"
serde_json = "1.0"
string-error = "0.1"
thiserror = "1.0"
56 changes: 56 additions & 0 deletions ursa_core/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use string_error::*;
use thiserror::Error as ThisError;

/// The common errors that can occur in Ursa
#[derive(ThisError, Debug)]
#[non_exhaustive]
pub enum UrsaError {
/// Convert IO errors
#[error("io error")]
IoError(#[from] core2::io::Error),
/// Convert format errors
#[error("fmt error")]
FmtError(#[from] std::fmt::Error),
/// Convert parse bool from string errors
#[error("parse bool error")]
ParseBoolError(#[from] std::str::ParseBoolError),
#[error("environment variable error")]
/// Convert environment variable errors
EnvVarError(#[from] std::env::VarError),
/// Convert json errors
#[error("json error")]
JsonError(#[from] serde_json::Error),
/// Convert cbor errors
#[error("cbor error")]
CborError(#[from] serde_cbor::Error),
/// Convert bare errors
#[error("bare error")]
BareError(#[from] serde_bare::error::Error),
/// Convert thread access errors
#[error("thread access error")]
ThreadAccessError(#[from] std::thread::AccessError),
/// Generic errors to handle anything that implements the std::error::Error trait
#[error("error: {0}")]
Kind(Box<dyn std::error::Error>),
}

impl From<String> for UrsaError {
fn from(value: String) -> Self {
Self::Kind(into_err(value))
}
}

impl From<&String> for UrsaError {
fn from(value: &String) -> Self {
Self::Kind(into_err(value.clone()))
}
}

impl From<&str> for UrsaError {
fn from(value: &str) -> Self {
Self::Kind(new_err(value))
}
}

/// Results returned from ursa components
pub type UrsaResult<T> = anyhow::Result<T, UrsaError>;
24 changes: 24 additions & 0 deletions ursa_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
//! This crate contains shared components used among the
//! Ursa library

#![deny(
unused_variables,
unused_imports,
unused_import_braces,
unused_parens,
unused_lifetimes,
unconditional_recursion,
unused_extern_crates,
trivial_casts,
trivial_numeric_casts
)]
#![cfg_attr(docsrs, feature(doc_cfg))]

mod error;

pub use serde;
pub use serde_bare;
pub use serde_cbor;
pub use serde_json;

/// The errors generated by ursa components
pub use error::*;