From 1323d0dccbb2ed7570e59b9b125f7b4a97ef7575 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 4 Feb 2017 13:03:42 +0100 Subject: [PATCH] fix(tests): use new serde map implementation No fun, this one. --- .cargo/config | 1 + Cargo.toml | 2 +- src/rust/cli/cmn.rs | 18 ++++++++---------- src/rust/lib.rs | 5 ++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.cargo/config b/.cargo/config index 87821012fa8..b281c9164aa 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,2 +1,3 @@ +paths = ["/Users/byron/dev/yup-oauth2"] [build] target-dir = "./target" diff --git a/Cargo.toml b/Cargo.toml index a1d12482333..e0ce12c3777 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ rustc-serialize = "*" yup-oauth2 = "*" serde = "*" serde_json = "*" -serde_macros = "*" +serde_derive = "*" strsim = "*" [dev-dependencies] diff --git a/src/rust/cli/cmn.rs b/src/rust/cli/cmn.rs index 59659ed6a0f..acabd6e9fe9 100644 --- a/src/rust/cli/cmn.rs +++ b/src/rust/cli/cmn.rs @@ -131,14 +131,12 @@ impl From<&'static str> for FieldCursor { } } -fn assure_entry<'a>(m: &'a mut json::Map, k: &'a String) -> &'a mut Value { - match m.get_mut(k) { - Some(v) => v, - None => { - m.insert(k.to_owned(), Value::Object(Default::default())); - m.get_mut(k).expect("value to exist") - } +fn assure_entry<'a, 'b>(m: &'a mut json::Map, k: &'b String) -> &'a mut Value { + if m.contains_key(k) { + return m.get_mut(k).expect("value to exist") } + m.insert(k.to_owned(), Value::Object(Default::default())); + m.get_mut(k).expect("value to exist") } impl FieldCursor { @@ -282,7 +280,7 @@ impl FieldCursor { Value::String(value.to_owned()), } }; - + match type_info.ctype { ComplexType::Pod => { if mapping.insert(field.to_owned(), to_jval(value, type_info.jtype, err)).is_some() { @@ -298,7 +296,7 @@ impl FieldCursor { ComplexType::Map => { let (key, value) = parse_kv_arg(value, err, true); let jval = to_jval(value.unwrap_or(""), type_info.jtype, err); - + match *assure_entry(mapping, &field) { Value::Object(ref mut value_map) => { @@ -314,7 +312,7 @@ impl FieldCursor { _ => unreachable!() } } - + pub fn num_fields(&self) -> usize { self.0.len() } diff --git a/src/rust/lib.rs b/src/rust/lib.rs index 3697eb8d516..f0629893d66 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -1,7 +1,4 @@ -#![feature(core,io,old_path, custom_derive, custom_attribute, plugin, slice_patterns, std_misc)] #![allow(dead_code, deprecated, unused_features, unused_variables, unused_imports)] -//! library with code shared by all generated implementations -#![plugin(serde_macros)] #[macro_use] extern crate clap; @@ -13,6 +10,8 @@ extern crate rustc_serialize; extern crate yup_oauth2 as oauth2; extern crate serde; extern crate serde_json; +#[macro_use] +extern crate serde_derive; extern crate strsim; // just pull it in the check if it compiles