From a87fab9ecc8587b85ba965b6c7e2c288576664e1 Mon Sep 17 00:00:00 2001 From: Thomas Bahn Date: Fri, 6 Feb 2015 15:28:22 +0100 Subject: [PATCH] Simplify some code using auto-deref --- src/json/mod.rs | 6 +++--- src/json/value.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/json/mod.rs b/src/json/mod.rs index 17d749bf..8d2670f7 100644 --- a/src/json/mod.rs +++ b/src/json/mod.rs @@ -285,7 +285,7 @@ fn main() { // 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(); } ``` @@ -1845,7 +1845,7 @@ mod bench { b.iter( || { 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)); for _ in range(0, count) { assert_eq!(parser.next(), Some(JsonEvent::ObjectStart)); @@ -1882,7 +1882,7 @@ mod bench { let src = json_str(count); 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)))); for _ in range(0, count) { diff --git a/src/json/value.rs b/src/json/value.rs index 9fee4671..9dc80b8f 100644 --- a/src/json/value.rs +++ b/src/json/value.rs @@ -533,7 +533,7 @@ pub trait ToJson { } impl ToJson for Value { - fn to_json(&self) -> Value { (*self).clone() } + fn to_json(&self) -> Value { self.clone() } } impl ToJson for isize { @@ -593,7 +593,7 @@ impl<'a> ToJson for &'a str { } 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 { @@ -644,7 +644,7 @@ impl ToJson for BTreeMap { fn to_json(&self) -> Value { let mut d = BTreeMap::new(); for (key, value) in self { - d.insert((*key).clone(), value.to_json()); + d.insert(key.clone(), value.to_json()); } Value::Object(d) } @@ -654,7 +654,7 @@ impl ToJson for HashMap { fn to_json(&self) -> Value { let mut d = BTreeMap::new(); for (key, value) in self { - d.insert((*key).clone(), value.to_json()); + d.insert(key.clone(), value.to_json()); } Value::Object(d) }