Macro invocation

Source
macro_rules! invocation {
    ($registration:expr) => { ... };
    ($registration:expr, $details:expr) => { ... };
    ($registration:expr, args: $args:expr) => { ... };
    ($registration:expr, kwargs: $kwargs:expr) => { ... };
    ($registration:expr, args: $args:expr, kwargs: $kwargs:expr) => { ... };
    ($registration:expr, $details:expr, args: $args:expr) => { ... };
    ($registration:expr, $details:expr, kwargs: $kwargs:expr) => { ... };
    ($registration:expr, $details:expr, $args:expr, $kwargs:expr) => { ... };
}
Expand description

§invocation Macro - wamp-proto

Macro for creating invocation messages easily with auto incrementing request id.

§Examples

use wamp_core::invocation;
use wamp_core::messages::Invocation;
use serde_json::{json, Value};

// Create a invocation message with default values
let invocation = invocation!(2);

// Which is the same as creating this:
let invocation2 = Invocation {
    request_id: 1,
    registration: 2,
    details: json!({}),
    args: Value::Null,
    kwargs: Value::Null
};

assert_eq!(invocation, invocation2);

// Some other ways you can construct it using the macro

// Create a invocation with custom details but empty args and kwargs
let _ = invocation!(2, json!( { "key": "value" } ));

// Create a invocation with custom args or kwargs, but empty details
let _ = invocation!(2, args: json!( [ 1, 2, 3 ] ));
let _ = invocation!(2, kwargs: json!( { "key": "value" } ));

// Create a invocation with custom args and kwargs, but empty details
let _ = invocation!(2, args: json!([ 1, 2, 3 ]), kwargs: json!({ "key": "value" }));

// Create a invocation with custom details, and either custom args OR custom kwargs
let _ = invocation!(2, json!( { "key": "value" } ), args: json!( [ 1, 2, 3 ] ));
let _ = invocation!(2, json!( { "key": "value" } ), kwargs: json!( { "key": "value" } ));

// Create a invocation with custom details, and both custom args and kwargs
// Note that when you use all "required" arguments for the struuct, keyword arguments should not be used for args and kwargs
let _ = invocation!(2, json!({}), json!([]), json!({}));