Skip to content

Commit e288627

Browse files
committed
more From impl for JsonValue
1 parent 6e2a663 commit e288627

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "json"
3-
version = "0.11.14"
3+
version = "0.11.15"
44
authors = ["Maciej Hirsz <[email protected]>", "Alec Embke <[email protected]>"]
55
description = "JSON implementation in Rust"
66
repository = "https://github.com/azuqua/json-rust"

src/object.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ pub struct Object {
9999
inner: IndexMap<String, JsonValue>
100100
}
101101

102+
impl From<IndexMap<String, JsonValue>> for Object {
103+
fn from(val: IndexMap<String, JsonValue>) -> Self {
104+
Object { inner: val }
105+
}
106+
}
107+
102108
impl Object {
103109
/// Create a new, empty instance of `Object`. Empty `Object` performs no
104110
/// allocation until a value is inserted into it.

src/value/implements.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use short::{ self, Short };
88
use number::Number;
99
use object::Object;
1010

11+
use indexmap::IndexMap;
12+
1113
use { JsonValue, Null };
1214

1315
macro_rules! implement_eq {
@@ -72,6 +74,12 @@ impl<'a> From<&'a str> for JsonValue {
7274
}
7375
}
7476

77+
impl<'a> From<&'a String> for JsonValue {
78+
fn from(val: &'a String) -> JsonValue {
79+
JsonValue::String(val.to_owned())
80+
}
81+
}
82+
7583
impl<T: Into<JsonValue>> From<Option<T>> for JsonValue {
7684
fn from(val: Option<T>) -> JsonValue {
7785
match val {
@@ -121,6 +129,13 @@ impl From<BTreeMap<String, JsonValue>> for JsonValue {
121129
}
122130
}
123131

132+
impl From<IndexMap<String, JsonValue>> for JsonValue {
133+
fn from(mut val: IndexMap<String, JsonValue>) -> JsonValue {
134+
JsonValue::Object(val.into())
135+
}
136+
}
137+
138+
124139
impl<'a> PartialEq<&'a str> for JsonValue {
125140
fn eq(&self, other: &&str) -> bool {
126141
match *self {

0 commit comments

Comments
 (0)