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.
This commit is contained in:
Thomas Bahn
2014-12-23 18:34:20 +01:00
parent 512a54e983
commit 17ffa65cb2
+6 -7
View File
@@ -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<K: StrAllocating, V: ser::Serialize>(mut self, k: K, v: V) -> ObjectBuilder {
self.object.insert(k.into_string(), value::to_value(&v));
pub fn insert<V: ser::Serialize>(mut self, k: String, v: V) -> ObjectBuilder {
self.object.insert(k, value::to_value(&v));
self
}
pub fn insert_array<S: StrAllocating>(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<S: StrAllocating>(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
}
}