From 17ffa65cb21d918e242af0882b11587a915055b8 Mon Sep 17 00:00:00 2001 From: Thomas Bahn Date: Tue, 23 Dec 2014 18:34:20 +0100 Subject: [PATCH] Replace StrAllocating with String type in function parameters The key parameter of the insert functions are of type String now. As insert requires ownership of its parameter `key` and StrAllocating being gone in rust these functions now communicate that ownership in their signature. As a result &str must be converted into a String at the caller instead of the callee. The Trait ToOwned isn't an alternative as it's a generalized Clone. StrAllocating simply has hidden an allocation or move. --- serde2/src/json/builder.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/serde2/src/json/builder.rs b/serde2/src/json/builder.rs index bed044da..a495eeaa 100644 --- a/serde2/src/json/builder.rs +++ b/serde2/src/json/builder.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::str::StrAllocating; use std::collections::BTreeMap; use ser::{mod, Serialize}; @@ -58,20 +57,20 @@ impl ObjectBuilder { Value::Object(self.object) } - pub fn insert(mut self, k: K, v: V) -> ObjectBuilder { - self.object.insert(k.into_string(), value::to_value(&v)); + pub fn insert(mut self, k: String, v: V) -> ObjectBuilder { + self.object.insert(k, value::to_value(&v)); self } - pub fn insert_array(mut self, key: S, f: |ArrayBuilder| -> ArrayBuilder) -> ObjectBuilder { + pub fn insert_array(mut self, key: String, f: |ArrayBuilder| -> ArrayBuilder) -> ObjectBuilder { let builder = ArrayBuilder::new(); - self.object.insert(key.into_string(), f(builder).unwrap()); + self.object.insert(key, f(builder).unwrap()); self } - pub fn insert_object(mut self, key: S, f: |ObjectBuilder| -> ObjectBuilder) -> ObjectBuilder { + pub fn insert_object(mut self, key: String, f: |ObjectBuilder| -> ObjectBuilder) -> ObjectBuilder { let builder = ObjectBuilder::new(); - self.object.insert(key.into_string(), f(builder).unwrap()); + self.object.insert(key, f(builder).unwrap()); self } }