File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ /// Pulls typed parameters from a slice of `Argument` using your `TryFromArgument`
2+ /// impls. Fails early with your `Signal::Failure(RuntimeError::simple(...))`.
3+ macro_rules! args {
4+ ( $args_ident: ident => $( $name: ident : $ty: ty ) ,+ $( , ) ?) => {
5+ // Arity check
6+ let __expected: usize = 0usize $( + { let _ = :: core:: any:: type_name:: <$ty>( ) ; 1usize } ) * ;
7+ if $args_ident. len( ) != __expected {
8+ return $crate:: context:: signal:: Signal :: Failure (
9+ $crate:: error:: RuntimeError :: simple(
10+ "InvalidArgumentRuntimeError" ,
11+ format!( "Expected {__expected} args but received {}" , $args_ident. len( ) ) ,
12+ )
13+ ) ;
14+ }
15+
16+ // Typed extraction
17+ let mut __i: usize = 0 ;
18+ $(
19+ let $name: $ty = match <
20+ $ty as $crate:: context:: argument:: TryFromArgument
21+ >:: try_from_argument( & $args_ident[ __i] ) {
22+ Ok ( v) => v,
23+ Err ( sig) => return sig,
24+ } ;
25+ __i += 1 ;
26+ ) +
27+ } ;
28+ }
29+
30+ /// Asserts there are no arguments.
31+ macro_rules! no_args {
32+ ( $args_ident: ident) => {
33+ if !$args_ident. is_empty( ) {
34+ return $crate:: context:: signal:: Signal :: Failure (
35+ $crate:: error:: RuntimeError :: simple(
36+ "InvalidArgumentRuntimeError" ,
37+ format!( "Expected 0 args but received {}" , $args_ident. len( ) ) ,
38+ )
39+ ) ;
40+ }
41+ } ;
42+ }
43+
44+ pub ( crate ) use args;
45+ pub ( crate ) use no_args;
You can’t perform that action at this time.
0 commit comments