diff options
| author | Victor M. Suarez <svmnotn@gmail.com> | 2016-01-02 20:47:10 -0500 |
|---|---|---|
| committer | Victor M. Suarez <svmnotn@gmail.com> | 2016-01-02 20:47:58 -0500 |
| commit | f6497ca3fbec4474084b8d13b39bd1bd1a87208d (patch) | |
| tree | e8b8ab55767dcf9932d36518b56e076c95772e28 /src/utils.rs | |
| parent | 0698f0255a1895460b0f497dd17b2ab809529d0a (diff) | |
ignore case for config enums. Fixes #738
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/utils.rs b/src/utils.rs index a13ca247964..83018a25ebb 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -198,13 +198,14 @@ macro_rules! impl_enum_decodable { ( $e:ident, $( $x:ident ),* ) => { impl ::rustc_serialize::Decodable for $e { fn decode<D: ::rustc_serialize::Decoder>(d: &mut D) -> Result<Self, D::Error> { + use std::ascii::AsciiExt; let s = try!(d.read_str()); - match &*s { - $( - stringify!($x) => Ok($e::$x), - )* - _ => Err(d.error("Bad variant")), - } + $( + if stringify!($x).eq_ignore_ascii_case(&s) { + return Ok($e::$x); + } + )* + Err(d.error("Bad variant")) } } @@ -212,12 +213,13 @@ macro_rules! impl_enum_decodable { type Err = &'static str; fn from_str(s: &str) -> Result<Self, Self::Err> { - match &*s { - $( - stringify!($x) => Ok($e::$x), - )* - _ => Err("Bad variant"), - } + use std::ascii::AsciiExt; + $( + if stringify!($x).eq_ignore_ascii_case(s) { + return Ok($e::$x); + } + )* + Err("Bad variant") } } |
