Skip to main content

proto_option

Macro proto_option 

Source
macro_rules! proto_option {
    ( $name:expr => { $($key:expr => $val:expr),* $(,)? } ) => { ... };
    ($name:expr => $val:expr) => { ... };
}
Expand description

This macro can be used to generate a ProtoOption with a concise syntax.

The input can be a single key => value, where the key should support Into FixedStr and the value should support Into OptionValue, or a bracketed series or key-value pairs to generate an OptionValue::Message for the value.

ยงExamples

use protify::*;

let option = proto_option!("is_cool" => true);
assert_eq!(option, ProtoOption { name: "is_cool".into(), value: true.into() });

let object_like_option = proto_option!("is_cool" => { "answer" => true });
assert_eq!(object_like_option.name, "is_cool");
assert_eq!(object_like_option.value, OptionValue::Message(option_message!("answer" => true)));