diff --git a/src/rcore/modes.rs b/src/rcore/modes.rs index 036b836..da51b34 100644 --- a/src/rcore/modes.rs +++ b/src/rcore/modes.rs @@ -18,6 +18,16 @@ pub trait Mode { ) -> Self::ParseResult; fn seal(result: Self::ParseResult) -> Result; + + fn xmap_err( + result: Self::ExtensionResult, + f: impl FnOnce(E0) -> E1, + ) -> Self::ExtensionResult; + + fn xbind( + result: Self::ExtensionResult, + f: impl FnOnce(A0) -> Result, + ) -> Self::ExtensionResult; } pub trait ParseMode { @@ -89,6 +99,20 @@ impl Mode for RegularMode { fn seal(result: Self::ParseResult) -> Result { result } + + fn xmap_err( + result: Self::ExtensionResult, + f: impl FnOnce(E0) -> E1, + ) -> Self::ExtensionResult { + result.map_err(f) + } + + fn xbind( + result: Self::ExtensionResult, + f: impl FnOnce(A0) -> Result, + ) -> Self::ExtensionResult { + result.and_then(f) + } } pub trait RegularFactory<'a, Ctx: Context<'a>>: diff --git a/src/rstd/inlining/modes.rs b/src/rstd/inlining/modes.rs index c6dbbcb..ce7ce18 100644 --- a/src/rstd/inlining/modes.rs +++ b/src/rstd/inlining/modes.rs @@ -26,6 +26,20 @@ impl Mode for InliningMode { fn seal(result: Self::ParseResult) -> Result { result.map(|(a, _)| a) } + + fn xmap_err( + result: Self::ExtensionResult, + f: impl FnOnce(E0) -> E1, + ) -> Self::ExtensionResult { + f(result) + } + + fn xbind( + result: Self::ExtensionResult, + _f: impl FnOnce(A0) -> Result, + ) -> Self::ExtensionResult { + result + } } impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> FactoryProxy<'a, Ctx>