From 3c58192957d282d3a402bf023f7c09d73bcbcf8b Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Sun, 21 Jun 2026 16:36:07 -0400 Subject: [PATCH] Add Result type with custom Error --- src/util/error.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/util/error.rs b/src/util/error.rs index 805cfa4..5c9c7e6 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -43,6 +43,8 @@ impl fmt::Display for ErrorLocation { } } +pub type Result = std::result::Result; + #[derive(Debug, Clone, Deserialize, Serialize, thiserror::Error)] pub struct Error { #[source] @@ -247,9 +249,9 @@ pub trait Contextualize { fn err_context(self, context: impl Into) -> R; } -impl> Contextualize> for Result { +impl> Contextualize> for std::result::Result { #[track_caller] - fn err_context(self, context: impl Into) -> Result { + fn err_context(self, context: impl Into) -> Result { // Closures can't (currently) `track_caller`, so a simple map_err doesn't work // See https://github.com/rust-lang/rust/issues/87417 match self { @@ -259,16 +261,16 @@ impl> Contextualize> for Result { } } -impl Contextualize> for Option { +impl Contextualize> for Option { #[track_caller] - fn err_context(self, context: impl Into) -> Result { + fn err_context(self, context: impl Into) -> Result { self.ok_or(Error::new_here(ErrorType::Error(context.into()))) } } -impl> Contextualize> for E { +impl> Contextualize> for E { #[track_caller] - fn err_context(self, context: impl Into) -> Result { + fn err_context(self, context: impl Into) -> Result { Err(self.into().with_context(context)) } }