From 22fbeca88a781aca7bcc965ac8189244497671d6 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Mon, 3 Mar 2025 23:00:19 -0500 Subject: Add some helpers for error handling --- src/lib.rs | 2 +- src/utils.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 49a3da3..3c00719 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ pub mod audio; pub mod net; pub mod save; -pub use utils::Erm; +pub use utils::{erm, Erm}; pub use anyhow::Context as ErmContext; #[cfg(target_arch = "wasm32")] diff --git a/src/utils.rs b/src/utils.rs index f5ce271..b2d1868 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,11 @@ use serde::{Serialize, Deserialize}; pub type Erm = anyhow::Result; -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +pub fn erm(e: E) -> Erm where E: std::error::Error + std::marker::Send + std::marker::Sync + 'static { + Err(anyhow::Error::from(e)) +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] pub enum Cardinal { North, South, -- cgit v1.2.3