Simplify some code using auto-deref
This commit is contained in:
parent
81f84a4ea4
commit
a87fab9ecc
@ -285,7 +285,7 @@ fn main() {
|
|||||||
|
|
||||||
// Deserialize like before.
|
// Deserialize like before.
|
||||||
|
|
||||||
let mut parser = json::Parser::new(json_str.as_slice().bytes());
|
let mut parser = json::Parser::new(json_str.bytes());
|
||||||
let deserialized: TestStruct1 = Deserialize::deserialize(&mut parser).unwrap();
|
let deserialized: TestStruct1 = Deserialize::deserialize(&mut parser).unwrap();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -1845,7 +1845,7 @@ mod bench {
|
|||||||
b.iter( || {
|
b.iter( || {
|
||||||
use serialize::json::{Parser, JsonEvent, StackElement};
|
use serialize::json::{Parser, JsonEvent, StackElement};
|
||||||
|
|
||||||
let mut parser = Parser::new(src.as_slice().chars());
|
let mut parser = Parser::new(src.chars());
|
||||||
assert_eq!(parser.next(), Some(JsonEvent::ArrayStart));
|
assert_eq!(parser.next(), Some(JsonEvent::ArrayStart));
|
||||||
for _ in range(0, count) {
|
for _ in range(0, count) {
|
||||||
assert_eq!(parser.next(), Some(JsonEvent::ObjectStart));
|
assert_eq!(parser.next(), Some(JsonEvent::ObjectStart));
|
||||||
@ -1882,7 +1882,7 @@ mod bench {
|
|||||||
let src = json_str(count);
|
let src = json_str(count);
|
||||||
|
|
||||||
b.iter( || {
|
b.iter( || {
|
||||||
let mut parser = Parser::new(src.as_slice().bytes());
|
let mut parser = Parser::new(src.bytes());
|
||||||
|
|
||||||
assert_eq!(parser.next(), Some(Ok(Token::SeqStart(0))));
|
assert_eq!(parser.next(), Some(Ok(Token::SeqStart(0))));
|
||||||
for _ in range(0, count) {
|
for _ in range(0, count) {
|
||||||
|
@ -533,7 +533,7 @@ pub trait ToJson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ToJson for Value {
|
impl ToJson for Value {
|
||||||
fn to_json(&self) -> Value { (*self).clone() }
|
fn to_json(&self) -> Value { self.clone() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJson for isize {
|
impl ToJson for isize {
|
||||||
@ -593,7 +593,7 @@ impl<'a> ToJson for &'a str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ToJson for String {
|
impl ToJson for String {
|
||||||
fn to_json(&self) -> Value { Value::String((*self).clone()) }
|
fn to_json(&self) -> Value { Value::String(self.clone()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! peel_to_json_tuple {
|
macro_rules! peel_to_json_tuple {
|
||||||
@ -644,7 +644,7 @@ impl<A:ToJson> ToJson for BTreeMap<String, A> {
|
|||||||
fn to_json(&self) -> Value {
|
fn to_json(&self) -> Value {
|
||||||
let mut d = BTreeMap::new();
|
let mut d = BTreeMap::new();
|
||||||
for (key, value) in self {
|
for (key, value) in self {
|
||||||
d.insert((*key).clone(), value.to_json());
|
d.insert(key.clone(), value.to_json());
|
||||||
}
|
}
|
||||||
Value::Object(d)
|
Value::Object(d)
|
||||||
}
|
}
|
||||||
@ -654,7 +654,7 @@ impl<A:ToJson> ToJson for HashMap<String, A> {
|
|||||||
fn to_json(&self) -> Value {
|
fn to_json(&self) -> Value {
|
||||||
let mut d = BTreeMap::new();
|
let mut d = BTreeMap::new();
|
||||||
for (key, value) in self {
|
for (key, value) in self {
|
||||||
d.insert((*key).clone(), value.to_json());
|
d.insert(key.clone(), value.to_json());
|
||||||
}
|
}
|
||||||
Value::Object(d)
|
Value::Object(d)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user