File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 11use std:: io;
22
3- use n0_error:: { StackError , e, meta} ;
3+ use n0_error:: { Err , StackError , e, meta} ;
44
55use self :: error:: CopyError ;
66use crate :: error:: { InvalidArgsError , OperationError } ;
@@ -27,6 +27,11 @@ fn main() {
2727 print ( err) ;
2828}
2929
30+ fn _some_fn ( ) -> Result < ( ) , CopyError > {
31+ // Err! macro works like e! but wraps in Err
32+ Err ! ( CopyError :: Read , io:: Error :: other( "yada" ) )
33+ }
34+
3035fn operation ( ) -> Result < ( ) , OperationError > {
3136 let res = copy ( ) ;
3237 res?;
@@ -67,13 +72,6 @@ pub mod error {
6772 Copy { source : CopyError } ,
6873 }
6974
70- #[ macro_export]
71- macro_rules! CopyError {
72- ( $variant: ident { $( $rest: tt) * } ) => {
73- e!( CopyError :: $variant { $( $rest) * } )
74- } ;
75- }
76-
7775 #[ n0_error:: add_meta]
7876 #[ derive( n0_error:: Error ) ]
7977 pub enum CopyError {
Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ macro_rules! e {
2121 } ;
2222}
2323
24+ /// Constructs an error enum/struct value and wraps it in `Err(err)`.
25+ ///
26+ /// See [`e`] for supported syntax.
27+ #[ macro_export]
28+ macro_rules! Err {
29+ ( $( $tt: tt) * ) => {
30+ Err ( e!( $( $tt) * ) )
31+ }
32+ }
33+
2434/// Propagates an error, adding formatted context.
2535///
2636/// - `whatever!("msg")` returns `Err(format_err!(...))`.
You can’t perform that action at this time.
0 commit comments