Skip to content

Commit

Permalink
more From impl for JsonValue
Browse files Browse the repository at this point in the history
  • Loading branch information
aembke committed Apr 19, 2019
1 parent 6e2a663 commit e288627
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "json"
version = "0.11.14"
version = "0.11.15"
authors = ["Maciej Hirsz <[email protected]>", "Alec Embke <[email protected]>"]
description = "JSON implementation in Rust"
repository = "https://github.com/azuqua/json-rust"
Expand Down
6 changes: 6 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ pub struct Object {
inner: IndexMap<String, JsonValue>
}

impl From<IndexMap<String, JsonValue>> for Object {
fn from(val: IndexMap<String, JsonValue>) -> Self {
Object { inner: val }
}
}

impl Object {
/// Create a new, empty instance of `Object`. Empty `Object` performs no
/// allocation until a value is inserted into it.
Expand Down
15 changes: 15 additions & 0 deletions src/value/implements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use short::{ self, Short };
use number::Number;
use object::Object;

use indexmap::IndexMap;

use { JsonValue, Null };

macro_rules! implement_eq {
Expand Down Expand Up @@ -72,6 +74,12 @@ impl<'a> From<&'a str> for JsonValue {
}
}

impl<'a> From<&'a String> for JsonValue {
fn from(val: &'a String) -> JsonValue {
JsonValue::String(val.to_owned())
}
}

impl<T: Into<JsonValue>> From<Option<T>> for JsonValue {
fn from(val: Option<T>) -> JsonValue {
match val {
Expand Down Expand Up @@ -121,6 +129,13 @@ impl From<BTreeMap<String, JsonValue>> for JsonValue {
}
}

impl From<IndexMap<String, JsonValue>> for JsonValue {
fn from(mut val: IndexMap<String, JsonValue>) -> JsonValue {
JsonValue::Object(val.into())
}
}


impl<'a> PartialEq<&'a str> for JsonValue {
fn eq(&self, other: &&str) -> bool {
match *self {
Expand Down

0 comments on commit e288627

Please sign in to comment.