macro_rules! param {
(Body $val:expr) => { ... };
(Body, $val:expr) => { ... };
($style:ident, $name:expr, ( $( ($($val:expr),* $(,)?) ),+ $(,)? )) => { ... };
($style:ident, $name:expr, ($($val:expr),+ $(,)?)) => { ... };
($style:ident, $name:expr, vec![ $( vec![ $($val:expr),* $(,)? ] ),* $(,)? ]) => { ... };
($style:ident, $name:expr, $val:expr) => { ... };
($style:path, $name:expr, ( $( ($($val:expr),* $(,)?) ),+ $(,)? )) => { ... };
($style:path, $name:expr, ($($val:expr),+ $(,)?)) => { ... };
($style:path, $name:expr, vec![ $( vec![ $($val:expr),* $(,)? ] ),* $(,)? ]) => { ... };
($style:path, $name:expr, $val:expr) => { ... };
}Expand description
Creates a Param with the given style, name, and values.
The macro supports two calling styles:
- Ident style (shorthand):
param!(QueryPair, "q", ...)
The style is automatically qualified toParamStyle::QueryPair - Path style (explicit):
param!(ParamStyle::QueryPair, "q", ...)
Use when the full path is preferred or whenParamStyleis in scope
§Parameter Styles
Common body type parameters and request styles:
Header: HTTP header (e.g.,"PRIVATE-TOKEN")Body: Request body payload (e.g., JSON or form data)QueryPair: URL query string parameterFieldList: Comma-separated field listTemplateValue: URI template substitutionKeyValuePair: Key-value pair in query or body
§Value Syntaxes
The macro supports four different value syntaxes:
- Single value:
param!(FieldList, "fl", "family-name") - Single tuple:
param!(QueryPair, "filter", ("status", "inactive")) - Multiple tuples:
param!(QueryPair, "q", (("key1", "val1"), ("key2", "val2"))) - Vec notation:
param!(FieldList, "fields", vec![vec!["field1"], vec!["field2"]]) - Body shorthand:
param!(Body &payload)(uses an empty key for raw curl-dsemantics)
§Examples
ⓘ
// Shorthand with single value (ident style)
param!(FieldList, "fl", "family-name")
// Shorthand with single tuple (ident style)
param!(QueryPair, "filter", ("status", "inactive"))
// Shorthand with multiple tuples (ident style)
param!(QueryPair, "q", (
("affiliation-org-name", "Lyrasis"),
("ror-org-id", "\"https://ror.org/01qz5mb56\""),
))
// Path style (explicit ParamStyle reference)
param!(ParamStyle::FieldList, "fl", "family-name")
// KeyValuePair (query string key-value pair)
param!(KeyValuePair, "per_page", "100")
param!(ParamStyle::KeyValuePair, "page", "2")
// Header parameter
param!(Header, "PRIVATE-TOKEN", &token)
// Body shorthand (raw body, no key)
param!(Body &payload)
// Body parameter (with key name)
param!(Body, "body", &payload)
// Vec notation
param!(QueryPair, "q", vec![
vec!["affiliation-org-name", "Lyrasis"],
])