Skip to content

Commit

Permalink
fix(tests): use new serde map implementation
Browse files Browse the repository at this point in the history
No fun, this one.
  • Loading branch information
Byron committed Feb 4, 2017
1 parent 7a611c3 commit 1323d0d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
paths = ["/Users/byron/dev/yup-oauth2"]
[build]
target-dir = "./target"
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ rustc-serialize = "*"
yup-oauth2 = "*"
serde = "*"
serde_json = "*"
serde_macros = "*"
serde_derive = "*"
strsim = "*"

[dev-dependencies]
Expand Down
18 changes: 8 additions & 10 deletions src/rust/cli/cmn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,12 @@ impl From<&'static str> for FieldCursor {
}
}

fn assure_entry<'a>(m: &'a mut json::Map<String, Value>, 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<String, Value>, 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 {
Expand Down Expand Up @@ -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() {
Expand All @@ -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) => {
Expand All @@ -314,7 +312,7 @@ impl FieldCursor {
_ => unreachable!()
}
}

pub fn num_fields(&self) -> usize {
self.0.len()
}
Expand Down
5 changes: 2 additions & 3 deletions src/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down

2 comments on commit 1323d0d

@dtolnay
Copy link

@dtolnay dtolnay commented on 1323d0d Feb 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're working on it - serde-rs/json#236

@Byron
Copy link
Owner Author

@Byron Byron commented on 1323d0d Feb 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for the pointer! I am subscribed to the issue and will use the entry-api once it lands :).

Please # to comment.