From e288627e8571901088fb95533ef662de87585c0c Mon Sep 17 00:00:00 2001 From: Alec Embke Date: Fri, 19 Apr 2019 09:14:25 -0700 Subject: [PATCH] more From impl for JsonValue --- Cargo.toml | 2 +- src/object.rs | 6 ++++++ src/value/implements.rs | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 38e5dda..6e851e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "json" -version = "0.11.14" +version = "0.11.15" authors = ["Maciej Hirsz ", "Alec Embke "] description = "JSON implementation in Rust" repository = "https://github.com/azuqua/json-rust" diff --git a/src/object.rs b/src/object.rs index 31a80c4..5c5f2db 100644 --- a/src/object.rs +++ b/src/object.rs @@ -99,6 +99,12 @@ pub struct Object { inner: IndexMap } +impl From> for Object { + fn from(val: IndexMap) -> 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. diff --git a/src/value/implements.rs b/src/value/implements.rs index 7d140c0..9970753 100644 --- a/src/value/implements.rs +++ b/src/value/implements.rs @@ -8,6 +8,8 @@ use short::{ self, Short }; use number::Number; use object::Object; +use indexmap::IndexMap; + use { JsonValue, Null }; macro_rules! implement_eq { @@ -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> From> for JsonValue { fn from(val: Option) -> JsonValue { match val { @@ -121,6 +129,13 @@ impl From> for JsonValue { } } +impl From> for JsonValue { + fn from(mut val: IndexMap) -> JsonValue { + JsonValue::Object(val.into()) + } +} + + impl<'a> PartialEq<&'a str> for JsonValue { fn eq(&self, other: &&str) -> bool { match *self {