From 8458c0f13e6255d6a508335bbbf721930afc0bdf Mon Sep 17 00:00:00 2001 From: Michael Lodder Date: Mon, 6 Feb 2023 13:37:05 -0700 Subject: [PATCH] Add convert from strings Signed-off-by: Michael Lodder --- ursa_core/Cargo.toml | 1 + ursa_core/src/error.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ursa_core/Cargo.toml b/ursa_core/Cargo.toml index b11dcfca..2a0daa2e 100644 --- a/ursa_core/Cargo.toml +++ b/ursa_core/Cargo.toml @@ -15,4 +15,5 @@ serde = "1.0" serde_bare = "0.5" serde_cbor = "0.11" serde_json = "1.0" +string-error = "0.1" thiserror = "1.0" diff --git a/ursa_core/src/error.rs b/ursa_core/src/error.rs index a75605c2..ca8b4abc 100644 --- a/ursa_core/src/error.rs +++ b/ursa_core/src/error.rs @@ -1,3 +1,4 @@ +use string_error::*; use thiserror::Error as ThisError; /// The common errors that can occur in Ursa @@ -32,5 +33,23 @@ pub enum UrsaError { Kind(Box), } +impl From 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 = anyhow::Result;