macro_rules! call {
($procedure:expr) => { ... };
($procedure:expr, $options:expr) => { ... };
($procedure:expr, args: $args:expr) => { ... };
($procedure:expr, kwargs: $kwargs:expr) => { ... };
($procedure:expr, args: $args:expr, kwargs: $kwargs:expr) => { ... };
($procedure:expr, $options:expr, args: $args:expr) => { ... };
($procedure:expr, $options:expr, kwargs: $kwargs:expr) => { ... };
($procedure:expr, $options:expr, $args:expr, $kwargs:expr) => { ... };
}
Expand description
§Call Macro - wamp-proto
Call message builder with thread safe auto-incrementing request-ids.
§Examples
use wamp_core::call;
use wamp_core::messages::Call;
use serde_json::{json, Value};
// Create a call message with default values
let call = call!("procedure");
// Which is the same as creating this:
let call2 = Call {
procedure: "procedure".to_string(),
request_id: 1,
options: json!({}),
args: Value::Null,
kwargs: Value::Null
};
assert_eq!(call, call2);
// Some other ways you can construct it using the macro
// Create a call with custom options but empty args and kwargs
let _ = call!("procedure", json!( { "key": "value" } ));
// Create a call with custom args or kwargs, but empty options
let _ = call!("procedure", args: json!( [ 1, 2, 3 ] ));
let _ = call!("procedure", kwargs: json!( { "key": "value" } ));
// Create a call with custom args and kwargs, but empty options
let _ = call!("procedure", args: json!([ 1, 2, 3 ]), kwargs: json!({ "key": "value" }));
// Create a call with custom options, and either custom args OR custom kwargs
let _ = call!("procedure", json!( { "key": "value" } ), args: json!( [ 1, 2, 3 ] ));
let _ = call!("procedure", json!( { "key": "value" } ), kwargs: json!( { "key": "value" } ));
// Create a call with custom options, 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 _ = call!("procedure", json!({}), json!([]), json!({}));