From 7dee5a64d574c2df12cdc3f27ff73523c5e534f5 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 14 Nov 2014 09:06:25 -0800 Subject: [PATCH] Allow the json::builder::ObjectBuilder to insert &str keys --- src/json/builder.rs | 4 ++-- src/json/value.rs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/json/builder.rs b/src/json/builder.rs index 78d1450a..b42da548 100644 --- a/src/json/builder.rs +++ b/src/json/builder.rs @@ -56,9 +56,9 @@ impl ObjectBuilder { Object(self.object) } - pub fn insert(self, key: String, value: T) -> ObjectBuilder { + pub fn insert(self, key: K, value: V) -> ObjectBuilder { let mut builder = self; - builder.object.insert(key, value.to_json()); + builder.object.insert(key.into_string(), value.to_json()); builder } diff --git a/src/json/value.rs b/src/json/value.rs index fc234191..7db9264f 100644 --- a/src/json/value.rs +++ b/src/json/value.rs @@ -639,3 +639,9 @@ impl ToJson for Option { } } } + +impl<'a, T: ToJson> ToJson for &'a T { + fn to_json(&self) -> Value { + (*self).to_json() + } +}