mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-23 02:28:00 +00:00
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:
+6
-7
@@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::str::StrAllocating;
|
||||
|
||||
use json::value::{ToJson, Value};
|
||||
|
||||
@@ -56,20 +55,20 @@ impl ObjectBuilder {
|
||||
Value::Object(self.object)
|
||||
}
|
||||
|
||||
pub fn insert<K: StrAllocating, V: ToJson>(self, key: K, value: V) -> ObjectBuilder {
|
||||
pub fn insert<V: ToJson>(self, key: String, value: V) -> ObjectBuilder {
|
||||
let mut builder = self;
|
||||
builder.object.insert(key.into_string(), value.to_json());
|
||||
builder.object.insert(key, value.to_json());
|
||||
builder
|
||||
}
|
||||
|
||||
pub fn insert_array<S: StrAllocating>(self, key: S, f: |ArrayBuilder| -> ArrayBuilder) -> ObjectBuilder {
|
||||
pub fn insert_array(self, key: String, f: |ArrayBuilder| -> ArrayBuilder) -> ObjectBuilder {
|
||||
let builder = ArrayBuilder::new();
|
||||
self.insert(key.into_string(), f(builder).unwrap())
|
||||
self.insert(key, f(builder).unwrap())
|
||||
}
|
||||
|
||||
pub fn insert_object<S: StrAllocating>(self, key: S, f: |ObjectBuilder| -> ObjectBuilder) -> ObjectBuilder {
|
||||
pub fn insert_object(self, key: String, f: |ObjectBuilder| -> ObjectBuilder) -> ObjectBuilder {
|
||||
let builder = ObjectBuilder::new();
|
||||
self.insert(key.into_string(), f(builder).unwrap())
|
||||
self.insert(key, f(builder).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user