Skip to content
Snippets Groups Projects

Refactor command to make is shorter

Merged DISSOUBRAY Nathan requested to merge refactor_command into master
1 file
+ 2
2
Compare changes
  • Side-by-side
  • Inline
+ 2
2
@@ -170,13 +170,13 @@ macro_rules! dragoon_command {
($state:expr, // the current state we are in
$variant:ident // the type of DragoonCommand we want to use
$(,)? // optional comma, allows to not leave a trailing comma when there is nothing behind
$($t:ident),*) // the list of the parameters for the given variant, separated by comma, 0 or more of them
$($variant_args:ident),*) // the list of the parameters for the given variant, separated by comma, 0 or more of them
// note that the sender is automatically added, since it's common to all the variants
=> {
{
let (sender, receiver) = oneshot::channel(); // create a channel
let cmd = DragoonCommand::$variant {$($t,)* sender}; // build the command
let cmd = DragoonCommand::$variant {$($variant_args,)* sender}; // build the command
// for example, when calling `dragoon_command!(state, Listen, multiaddr)` the expanded result will be:
// `let cmd = DragoonCommand::Listen {multiaddr, sender}`
// note that as variant and all the t are captured as ident, there is no need to write the corresponding field name for each variable
Loading