macro_rules! operation { (@builder $(#[$outer:meta])* // The name of the operation and any generic params along with their constraints $name:ident<$($generic:ident: $first_constraint:ident $(+ $constraint:ident)* ),* $(+ $lt:lifetime)?>, // The client client: $client:ty, // The required fields that will be used in the constructor @required $($required:ident: $rtype:ty,)* // The optional fields that will have generated setters @optional $($optional:ident: $otype:ty,)* // The optional fields which won't have generated setters @nosetter $($nosetter:ident: $nstype:ty),* ) => { ... }; (#[stream] $(#[$outer:meta])* $name:ident, client: $client:ty, $($required:ident: $rtype:ty,)* $(?$optional:ident: $otype:ty),*) => { ... }; (#[stream] $(#[$outer:meta])* $name:ident, client: $client:ty, $($required:ident: $rtype:ty,)* $(?$optional:ident: $otype:ty,)* $(#[skip]$nosetter:ident: $nstype:ty),* ) => { ... }; ($(#[$outer:meta])* $name:ident<$($generic:ident: $first_constraint:ident $(+ $constraint:ident)* ),* $(+ $lt:lifetime)?>, client: $client:ty, @required $($required:ident: $rtype:ty,)* @optional $($optional:ident: $otype:ty,)* @nosetter $($nosetter:ident: $nstype:ty),* ) => { ... }; ($(#[$outer:meta])* $name:ident, client: $client:ty, $($required:ident: $rtype:ty,)* $(?$optional:ident: $otype:ty),*) => { ... }; ($(#[$outer:meta])* $name:ident<$($generic:ident: $first_constraint:ident $(+ $constraint:ident)*),* $(+ $lt:lifetime)?>, client: $client:ty, $($required:ident: $rtype:ty,)* $(?$optional:ident: $otype:ty,)* $(#[skip] $nosetter:ident: $nstype:ty),*) => { ... }; }
Expand description
Helper for constructing operations
For the following code:
azure_core::operation! {
CreateCollection,
client: DatabaseClient,
collection_name: String,
?consistency_level: u32
}
The following code will be generated
#[derive(Debug, Clone)]
pub struct CreateCollectionBuilder {
client: DatabaseClient,
collection_name: String,
consistency_level: Option<u32>,
context: Context,
}
impl CreateCollectionBuilder {
pub(crate) fn new(
client: DatabaseClient,
collection_name: String,
) -> Self {
Self {
client,
collection_name,
consistency_level: None,
context: Context::new(),
}
}
setters! {
consistency_level: u32 => Some(consistency_level),
context: Context => context,
}
}
impl std::future::IntoFuture for CreateCollectionBuilder {
type IntoFuture = CreateCollection;
type Output = <CreateCollection as std::future::Future>::Output;
fn into_future(self) -> Self::IntoFuture {
Self::into_future(self)
}
}
/// The future returned by calling `into_future` on the builder.
pub type CreateCollection =
futures::future::BoxFuture<'static, azure_core::Result<CreateCollectionResponse>>;
Additionally, #[stream]
can be used before the operation name to generate code appropriate for list operations
and #[skip]
can be used at the end of the list of options for options where we should not generate a setter.