Gitlab updates will be applied at 1:30pm, (17:30 UTC), today. No downtime expected.

Commit 2199ef3a authored by Ben Boeckel's avatar Ben Boeckel

macros: support multiple choices for deserializing strings

While `|` would be preferred, in macros, `expr` matches may include `|`
and therefore may not be followed by `|`. The only other options are
`,`, `;`, or `=>`. The comma is already used for separating variants and
the arrow for the variant/string separation. Semicolon is the only one
left, but it is also used for "or" in Prolog.
parent 754f0bd0
......@@ -36,7 +36,7 @@ macro_rules! impl_id {
}
macro_rules! enum_serialize {
( $name:ident -> $desc:expr, $( $value:ident => $str:expr, )+ ) => {
( $name:ident -> $desc:expr, $( $value:ident => $str:expr $( ; $opt:expr )*, )+ ) => {
impl $name {
/// String representation of the variant.
pub fn as_str(&self) -> &'static str {
......@@ -61,7 +61,7 @@ macro_rules! enum_serialize {
let val = String::deserialize(deserializer)?;
match val.as_str() {
$( $str => Ok($name::$value), )*
$( $str $( | $opt )* => Ok($name::$value), )*
v => {
error!(target: "gitlab", concat!("unknown ", $desc, " from gitlab: {}"), v);
Err(D::Error::invalid_value(Unexpected::Other("enumeration value"),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment