mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-23 23:27:59 +00:00
Use deref coercions when possible
This commit is contained in:
+2
-2
@@ -381,7 +381,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
}
|
||||
|
||||
let buf = &[n1, try!(self.decode_hex_escape())];
|
||||
match ::unicode::str::utf16_items(buf.as_slice()).next() {
|
||||
match ::unicode::str::utf16_items(buf).next() {
|
||||
Some(Utf16Item::ScalarValue(c)) => c,
|
||||
_ => {
|
||||
return Err(self.error(ErrorCode::LoneLeadingSurrogateInHexEscape));
|
||||
@@ -410,7 +410,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
match ch {
|
||||
b'"' => {
|
||||
self.bump();
|
||||
return Ok(str::from_utf8(self.buf.as_slice()).unwrap());
|
||||
return Ok(str::from_utf8(&self.buf).unwrap());
|
||||
}
|
||||
b'\\' => {
|
||||
escape = true;
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ impl error::Error for Error {
|
||||
match *self {
|
||||
Error::SyntaxError(..) => "syntax error",
|
||||
Error::IoError(ref error) => error.description(),
|
||||
Error::ExpectedError(ref expected, _) => expected.as_slice(),
|
||||
Error::ExpectedError(ref expected, _) => &expected,
|
||||
Error::MissingFieldError(_) => "missing field",
|
||||
Error::UnknownVariantError(_) => "unknown variant",
|
||||
}
|
||||
|
||||
+6
-6
@@ -232,7 +232,7 @@ fn main() {
|
||||
|
||||
// To deserialize use the `json::from_str` function.
|
||||
|
||||
let deserialized_object: TestStruct1 = match json::from_str(serialized_str.as_slice()) {
|
||||
let deserialized_object: TestStruct1 = match json::from_str(&serialized_str) {
|
||||
Ok(deserialized_object) => deserialized_object,
|
||||
Err(e) => panic!("json deserialization error: {:?}", e),
|
||||
};
|
||||
@@ -1379,7 +1379,7 @@ mod tests {
|
||||
hm.serialize(&mut serializer).unwrap();
|
||||
}
|
||||
let bytes = mem_buf.unwrap();
|
||||
let json_str = from_utf8(bytes.as_slice()).unwrap();
|
||||
let json_str = from_utf8(&bytes).unwrap();
|
||||
let _json_value: Value = from_str(json_str).unwrap();
|
||||
}
|
||||
#[test]
|
||||
@@ -1394,7 +1394,7 @@ mod tests {
|
||||
hm.serialize(&mut serializer).unwrap()
|
||||
}
|
||||
let bytes = mem_buf.unwrap();
|
||||
let json_str = from_utf8(bytes.as_slice()).unwrap();
|
||||
let json_str = from_utf8(&bytes).unwrap();
|
||||
let _json_value: Value = from_str(json_str).unwrap();
|
||||
}
|
||||
|
||||
@@ -1419,7 +1419,7 @@ mod tests {
|
||||
None => { break; }
|
||||
};
|
||||
let (ref expected_evt, ref expected_stack) = expected[i];
|
||||
if !parser.stack().is_equal_to(expected_stack.as_slice()) {
|
||||
if !parser.stack().is_equal_to(&expected_stack) {
|
||||
panic!("Parser stack is not equal to {}", expected_stack);
|
||||
}
|
||||
assert_eq!(&evt, expected_evt);
|
||||
@@ -1827,7 +1827,7 @@ mod bench {
|
||||
let src = json_str(count);
|
||||
let json = encoder_json(count);
|
||||
b.iter(|| {
|
||||
assert_eq!(json, serialize::json::from_str(src.as_slice()).unwrap());
|
||||
assert_eq!(json, serialize::json::from_str(&src).unwrap());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1835,7 +1835,7 @@ mod bench {
|
||||
let src = json_str(count);
|
||||
let json = encoder_json(count);
|
||||
b.iter(|| {
|
||||
assert_eq!(json, serialize::json::from_str(src.as_slice()).unwrap());
|
||||
assert_eq!(json, serialize::json::from_str(&src).unwrap());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -53,14 +53,14 @@ fn escape_char<W: Writer>(wr: &mut W, v: char) -> IoResult<()> {
|
||||
fn fmt_f32_or_null<W: Writer>(wr: &mut W, v: f32) -> IoResult<()> {
|
||||
match v.classify() {
|
||||
FpCategory::Nan | FpCategory::Infinite => wr.write_str("null"),
|
||||
_ => wr.write_str(f32::to_str_digits(v, 6).as_slice()),
|
||||
_ => wr.write_str(&f32::to_str_digits(v, 6)),
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_f64_or_null<W: Writer>(wr: &mut W, v: f64) -> IoResult<()> {
|
||||
match v.classify() {
|
||||
FpCategory::Nan | FpCategory::Infinite => wr.write_str("null"),
|
||||
_ => wr.write_str(f64::to_str_digits(v, 6).as_slice()),
|
||||
_ => wr.write_str(&f64::to_str_digits(v, 6)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -43,7 +43,7 @@ impl Value {
|
||||
pub fn to_pretty_string(&self) -> String {
|
||||
let mut wr = Vec::new();
|
||||
self.to_pretty_writer(wr.by_ref()).unwrap();
|
||||
str::from_utf8(wr.as_slice()).unwrap().to_string()
|
||||
str::from_utf8(&wr).unwrap().to_string()
|
||||
}
|
||||
|
||||
/// If the Json value is an Object, returns the value associated with the provided key.
|
||||
@@ -130,7 +130,7 @@ impl Value {
|
||||
/// Returns None otherwise.
|
||||
pub fn as_string<'a>(&'a self) -> Option<&'a str> {
|
||||
match *self {
|
||||
Value::String(ref s) => Some(s.as_slice()),
|
||||
Value::String(ref s) => Some(&s),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ impl ToString for Value {
|
||||
fn to_string(&self) -> String {
|
||||
let mut wr = Vec::new();
|
||||
self.to_writer(wr.by_ref()).unwrap();
|
||||
str::from_utf8(wr.as_slice()).unwrap().to_string()
|
||||
str::from_utf8(&wr).unwrap().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user