diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-22 23:59:31 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-22 23:59:31 +0800 |
| commit | 443ffe86485519a218997955335cde142733f88f (patch) | |
| tree | ef331749338c8653ac8a241bfd1cf83cd0683468 /mingling_macros/src/lib.rs | |
| parent | 31b5abfc96013309530025b751293c7de916dcf3 (diff) | |
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()`.
Diffstat (limited to 'mingling_macros/src/lib.rs')
| -rw-r--r-- | mingling_macros/src/lib.rs | 15 |
1 files changed, 8 insertions, 7 deletions
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<G>, ChainProcess<G>>` -/// and want to propagate the error case as an early return. +/// It is useful inside chain functions where you have a `Result<SomeType, SomeType>` +/// 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<ThisProgram> { -/// 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) |
