From 443ffe86485519a218997955335cde142733f88f Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 22 Jun 2026 23:59:31 +0800 Subject: Make route! macro auto-convert error types `route!()` now calls `Groupped::to_chain()` on the error branch, removing the need for callers to pre-convert with `.to_chain()` or `.to_render()`. --- mingling_macros/src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'mingling_macros/src/lib.rs') diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index 204d59c..3b33f09 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -405,12 +405,13 @@ pub fn pack_err(input: TokenStream) -> TokenStream { /// ```rust,ignore /// match expr { /// Ok(r) => r, -/// Err(e) => return e, +/// Err(e) => return ::mingling::Groupped::to_chain(e), /// } /// ``` /// -/// It is useful inside chain functions where you have a `Result, ChainProcess>` -/// and want to propagate the error case as an early return. +/// It is useful inside chain functions where you have a `Result` +/// where both types implement `Groupped` and want to propagate the error case +/// as an early return via `Groupped::to_chain()`. /// /// # Example /// @@ -419,9 +420,9 @@ pub fn pack_err(input: TokenStream) -> TokenStream { /// /// #[chain] /// fn process(prev: SomeEntry) -> ChainProcess { -/// let value = route!(try_something().ok_or(ErrorEntry::new("failed".into()).to_render())); -/// // value is the Ok(ChainProcess) from try_something() -/// value +/// let value = route!(current_dir().map_err(|e| ErrorEntry::new(e.to_string_lossy().to_string()))); +/// // value is the PathBuf from current_dir() +/// value.to_chain() /// } /// ``` #[cfg(feature = "extra_macros")] @@ -431,7 +432,7 @@ pub fn route(input: TokenStream) -> TokenStream { let expanded = quote! { match #expr { Ok(r) => r, - Err(e) => return e, + Err(e) => return ::mingling::Groupped::to_chain(e), } }; TokenStream::from(expanded) -- cgit