macro_rules! oneof {
(
$name:expr,
required,
$($tokens:tt)*
) => { ... };
(
$name:expr,
$($tokens:tt)*
) => { ... };
}Expand description
Evaluates to a Oneof instance.
The first argument is the name of the oneof, followed by a comma, optionally followed by this oneofâs options defined as options = $options where $options should evaluate to IntoIter<Item = ProtoOption>, followed by the fields for this oneof, which are defined as a comma separated list of $number:literal => $field:expr, with $field evaluating to a FieldBuilder or include($reusable_fields:expr), where $reusable_fields is the expansion of a call to reusable_fields.
If you want to add the ârequiredâ rule to this oneof (meaning at least one of the choices will need to be set to pass validation), you must place the ârequiredâ keyword right after the name of the oneof.
§Examples
use protoschema::{oneof, proto_option, string, reusable_fields, uint64};
let my_common_fields = reusable_fields!(
1 => uint64!("id"),
2 => string!("username"),
3 => string!("email")
);
let my_opt = proto_option("my_opt", true);
let my_list_of_options = [ my_opt.clone(), my_opt.clone() ];
let oneof = oneof!(
"my_oneof",
required,
options = [ my_opt ], // Or `options = my_list_of_options.clone()`
// Add a normal field
1 => string!("abc"),
// Include some reusable fields
include(my_common_fields)
);