Skip to content

Commit

Permalink
Added JsonKey to abstract over usize/String
Browse files Browse the repository at this point in the history
Arrays have usize indices, obejcts use String.
To make them comparable, it's most efficient to
use an enum.
  • Loading branch information
Byron committed Jan 15, 2017
1 parent 837f56f commit 5ac03ce
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/traitimpls/json.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use traitdef::Value;
use rustc_serialize::json::Json;

pub enum JsonKey {
String(String)
}

impl Value for Json {
type Item = Json;
type Key = String;
type Key = JsonKey;
fn items<'a>(&'a self) -> Option<Box<Iterator<Item = (Self::Key, &'a Self::Item)> + 'a>> {
match *self {
Json::Object(ref inner) => Some(Box::new(inner.iter().map(|(s, v)| (s.clone(), v)))),
Json::Object(ref inner) => Some(Box::new(inner.iter().map(|(s, v)| (JsonKey::String(s.clone()), v)))),
_ => unimplemented!(),

}
Expand Down

0 comments on commit 5ac03ce

Please sign in to comment.