diff --git a/src/value/from.rs b/src/value/from.rs index ed1e3338b..2dae925a1 100644 --- a/src/value/from.rs +++ b/src/value/from.rs @@ -1,8 +1,8 @@ use super::Value; use crate::map::Map; use crate::number::Number; -use alloc::borrow::Cow; -use alloc::string::{String, ToString}; +use alloc::borrow::{Cow, ToOwned}; +use alloc::string::String; use alloc::vec::Vec; macro_rules! from_integer { @@ -85,7 +85,7 @@ impl From for Value { /// ``` /// use serde_json::Value; /// - /// let s: String = "lorem".to_string(); + /// let s: String = "lorem".to_owned(); /// let x: Value = s.into(); /// ``` fn from(f: String) -> Self { @@ -105,7 +105,7 @@ impl From<&str> for Value { /// let x: Value = s.into(); /// ``` fn from(f: &str) -> Self { - Value::String(f.to_string()) + Value::String(f.to_owned()) } } @@ -126,7 +126,7 @@ impl<'a> From> for Value { /// use serde_json::Value; /// use std::borrow::Cow; /// - /// let s: Cow = Cow::Owned("lorem".to_string()); + /// let s: Cow = Cow::Owned("lorem".to_owned()); /// let x: Value = s.into(); /// ``` fn from(f: Cow<'a, str>) -> Self { @@ -159,7 +159,7 @@ impl From> for Value { /// use serde_json::{Map, Value}; /// /// let mut m = Map::new(); - /// m.insert("Lorem".to_string(), "ipsum".into()); + /// m.insert("Lorem".to_owned(), "ipsum".into()); /// let x: Value = m.into(); /// ``` fn from(f: Map) -> Self { diff --git a/tests/map.rs b/tests/map.rs index c3c64d70b..aa3cb2549 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -20,7 +20,7 @@ fn test_preserve_order() { fn test_shift_insert() { let mut v: Value = from_str(r#"{"b":null,"a":null,"c":null}"#).unwrap(); let val = v.as_object_mut().unwrap(); - val.shift_insert(0, "d".to_string(), Value::Null); + val.shift_insert(0, "d".to_owned(), Value::Null); let keys: Vec<_> = val.keys().collect(); assert_eq!(keys, &["d", "b", "a", "c"]); diff --git a/tests/test.rs b/tests/test.rs index dc8c3c22f..d41a2336a 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -269,11 +269,11 @@ fn test_write_list() { fn test_write_object() { test_encode_ok(&[ (treemap!(), "{}"), - (treemap!("a".to_string() => true), "{\"a\":true}"), + (treemap!("a".to_owned() => true), "{\"a\":true}"), ( treemap!( - "a".to_string() => true, - "b".to_string() => false, + "a".to_owned() => true, + "b".to_owned() => false, ), "{\"a\":true,\"b\":false}", ), @@ -282,44 +282,44 @@ fn test_write_object() { test_encode_ok(&[ ( treemap![ - "a".to_string() => treemap![], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "a".to_owned() => treemap![], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], "{\"a\":{},\"b\":{},\"c\":{}}", ), ( treemap![ - "a".to_string() => treemap![ - "a".to_string() => treemap!["a" => vec![1,2,3]], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "a".to_owned() => treemap![ + "a".to_owned() => treemap!["a" => vec![1,2,3]], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], "{\"a\":{\"a\":{\"a\":[1,2,3]},\"b\":{},\"c\":{}},\"b\":{},\"c\":{}}", ), ( treemap![ - "a".to_string() => treemap![], - "b".to_string() => treemap![ - "a".to_string() => treemap!["a" => vec![1,2,3]], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "a".to_owned() => treemap![], + "b".to_owned() => treemap![ + "a".to_owned() => treemap!["a" => vec![1,2,3]], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], - "c".to_string() => treemap![], + "c".to_owned() => treemap![], ], "{\"a\":{},\"b\":{\"a\":{\"a\":[1,2,3]},\"b\":{},\"c\":{}},\"c\":{}}", ), ( treemap![ - "a".to_string() => treemap![], - "b".to_string() => treemap![], - "c".to_string() => treemap![ - "a".to_string() => treemap!["a" => vec![1,2,3]], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "a".to_owned() => treemap![], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![ + "a".to_owned() => treemap!["a" => vec![1,2,3]], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], ], "{\"a\":{},\"b\":{},\"c\":{\"a\":{\"a\":[1,2,3]},\"b\":{},\"c\":{}}}", @@ -331,9 +331,9 @@ fn test_write_object() { test_pretty_encode_ok(&[ ( treemap![ - "a".to_string() => treemap![], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "a".to_owned() => treemap![], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], pretty_str!({ "a": {}, @@ -343,13 +343,13 @@ fn test_write_object() { ), ( treemap![ - "a".to_string() => treemap![ - "a".to_string() => treemap!["a" => vec![1,2,3]], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "a".to_owned() => treemap![ + "a".to_owned() => treemap!["a" => vec![1,2,3]], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], pretty_str!({ "a": { @@ -369,13 +369,13 @@ fn test_write_object() { ), ( treemap![ - "a".to_string() => treemap![], - "b".to_string() => treemap![ - "a".to_string() => treemap!["a" => vec![1,2,3]], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "a".to_owned() => treemap![], + "b".to_owned() => treemap![ + "a".to_owned() => treemap!["a" => vec![1,2,3]], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], - "c".to_string() => treemap![], + "c".to_owned() => treemap![], ], pretty_str!({ "a": {}, @@ -395,12 +395,12 @@ fn test_write_object() { ), ( treemap![ - "a".to_string() => treemap![], - "b".to_string() => treemap![], - "c".to_string() => treemap![ - "a".to_string() => treemap!["a" => vec![1,2,3]], - "b".to_string() => treemap![], - "c".to_string() => treemap![], + "a".to_owned() => treemap![], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![ + "a".to_owned() => treemap!["a" => vec![1,2,3]], + "b".to_owned() => treemap![], + "c".to_owned() => treemap![], ], ], pretty_str!({ @@ -424,15 +424,15 @@ fn test_write_object() { test_pretty_encode_ok(&[ (treemap!(), "{}"), ( - treemap!("a".to_string() => true), + treemap!("a".to_owned() => true), pretty_str!({ "a": true }), ), ( treemap!( - "a".to_string() => true, - "b".to_string() => false, + "a".to_owned() => true, + "b".to_owned() => false, ), pretty_str!( { "a": true, @@ -493,26 +493,26 @@ fn test_write_enum() { test_encode_ok(&[ (Animal::Dog, "\"Dog\""), ( - Animal::Frog("Henry".to_string(), vec![]), + Animal::Frog("Henry".to_owned(), vec![]), "{\"Frog\":[\"Henry\",[]]}", ), ( - Animal::Frog("Henry".to_string(), vec![349]), + Animal::Frog("Henry".to_owned(), vec![349]), "{\"Frog\":[\"Henry\",[349]]}", ), ( - Animal::Frog("Henry".to_string(), vec![349, 102]), + Animal::Frog("Henry".to_owned(), vec![349, 102]), "{\"Frog\":[\"Henry\",[349,102]]}", ), ( Animal::Cat { age: 5, - name: "Kate".to_string(), + name: "Kate".to_owned(), }, "{\"Cat\":{\"age\":5,\"name\":\"Kate\"}}", ), ( - Animal::AntHive(vec!["Bob".to_string(), "Stuart".to_string()]), + Animal::AntHive(vec!["Bob".to_owned(), "Stuart".to_owned()]), "{\"AntHive\":[\"Bob\",\"Stuart\"]}", ), ]); @@ -520,7 +520,7 @@ fn test_write_enum() { test_pretty_encode_ok(&[ (Animal::Dog, "\"Dog\""), ( - Animal::Frog("Henry".to_string(), vec![]), + Animal::Frog("Henry".to_owned(), vec![]), pretty_str!({ "Frog": [ "Henry", @@ -529,7 +529,7 @@ fn test_write_enum() { }), ), ( - Animal::Frog("Henry".to_string(), vec![349]), + Animal::Frog("Henry".to_owned(), vec![349]), pretty_str!({ "Frog": [ "Henry", @@ -540,7 +540,7 @@ fn test_write_enum() { }), ), ( - Animal::Frog("Henry".to_string(), vec![349, 102]), + Animal::Frog("Henry".to_owned(), vec![349, 102]), pretty_str!({ "Frog": [ "Henry", @@ -1117,16 +1117,16 @@ fn test_parse_string() { test_parse_ok(vec![ ("\"\"", String::new()), - ("\"foo\"", "foo".to_string()), - (" \"foo\" ", "foo".to_string()), - ("\"\\\"\"", "\"".to_string()), - ("\"\\b\"", "\x08".to_string()), - ("\"\\n\"", "\n".to_string()), - ("\"\\r\"", "\r".to_string()), - ("\"\\t\"", "\t".to_string()), - ("\"\\u12ab\"", "\u{12ab}".to_string()), - ("\"\\uAB12\"", "\u{AB12}".to_string()), - ("\"\\uD83C\\uDF95\"", "\u{1F395}".to_string()), + ("\"foo\"", "foo".to_owned()), + (" \"foo\" ", "foo".to_owned()), + ("\"\\\"\"", "\"".to_owned()), + ("\"\\b\"", "\x08".to_owned()), + ("\"\\n\"", "\n".to_owned()), + ("\"\\r\"", "\r".to_owned()), + ("\"\\t\"", "\t".to_owned()), + ("\"\\u12ab\"", "\u{12ab}".to_owned()), + ("\"\\uAB12\"", "\u{AB12}".to_owned()), + ("\"\\uD83C\\uDF95\"", "\u{1F395}".to_owned()), ]); } @@ -1184,24 +1184,24 @@ fn test_parse_object() { test_parse_ok(vec![ ("{}", treemap!()), ("{ }", treemap!()), - ("{\"a\":3}", treemap!("a".to_string() => 3u64)), - ("{ \"a\" : 3 }", treemap!("a".to_string() => 3)), + ("{\"a\":3}", treemap!("a".to_owned() => 3u64)), + ("{ \"a\" : 3 }", treemap!("a".to_owned() => 3)), ( "{\"a\":3,\"b\":4}", - treemap!("a".to_string() => 3, "b".to_string() => 4), + treemap!("a".to_owned() => 3, "b".to_owned() => 4), ), ( " { \"a\" : 3 , \"b\" : 4 } ", - treemap!("a".to_string() => 3, "b".to_string() => 4), + treemap!("a".to_owned() => 3, "b".to_owned() => 4), ), ]); test_parse_ok(vec![( "{\"a\": {\"b\": 3, \"c\": 4}}", treemap!( - "a".to_string() => treemap!( - "b".to_string() => 3u64, - "c".to_string() => 4, + "a".to_owned() => treemap!( + "b".to_owned() => 3u64, + "c".to_owned() => 4, ), ), )]); @@ -1248,7 +1248,7 @@ fn test_parse_struct() { inner: vec![Inner { a: (), b: 2, - c: vec!["abc".to_string(), "xyz".to_string()], + c: vec!["abc".to_owned(), "xyz".to_owned()], }], }, ), @@ -1269,7 +1269,7 @@ fn test_parse_struct() { inner: vec![Inner { a: (), b: 2, - c: vec!["abc".to_string(), "xyz".to_string()], + c: vec!["abc".to_owned(), "xyz".to_owned()], }], } ); @@ -1283,7 +1283,7 @@ fn test_parse_struct() { fn test_parse_option() { test_parse_ok(vec![ ("null", None::), - ("\"jodhpurs\"", Some("jodhpurs".to_string())), + ("\"jodhpurs\"", Some("jodhpurs".to_owned())), ]); #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -1338,29 +1338,29 @@ fn test_parse_enum() { (" \"Dog\" ", Animal::Dog), ( "{\"Frog\":[\"Henry\",[]]}", - Animal::Frog("Henry".to_string(), vec![]), + Animal::Frog("Henry".to_owned(), vec![]), ), ( " { \"Frog\": [ \"Henry\" , [ 349, 102 ] ] } ", - Animal::Frog("Henry".to_string(), vec![349, 102]), + Animal::Frog("Henry".to_owned(), vec![349, 102]), ), ( "{\"Cat\": {\"age\": 5, \"name\": \"Kate\"}}", Animal::Cat { age: 5, - name: "Kate".to_string(), + name: "Kate".to_owned(), }, ), ( " { \"Cat\" : { \"age\" : 5 , \"name\" : \"Kate\" } } ", Animal::Cat { age: 5, - name: "Kate".to_string(), + name: "Kate".to_owned(), }, ), ( " { \"AntHive\" : [\"Bob\", \"Stuart\"] } ", - Animal::AntHive(vec!["Bob".to_string(), "Stuart".to_string()]), + Animal::AntHive(vec!["Bob".to_owned(), "Stuart".to_owned()]), ), ]); @@ -1377,8 +1377,8 @@ fn test_parse_enum() { "}" ), treemap!( - "a".to_string() => Animal::Dog, - "b".to_string() => Animal::Frog("Henry".to_string(), vec![]), + "a".to_owned() => Animal::Dog, + "b".to_owned() => Animal::Frog("Henry".to_owned(), vec![]), ), )]); } @@ -1653,7 +1653,7 @@ fn test_deserialize_from_stream() { let mut stream = TcpStream::connect("localhost:20000").unwrap(); let request = Message { - message: "hi there".to_string(), + message: "hi there".to_owned(), }; to_writer(&mut stream, &request).unwrap(); @@ -1679,20 +1679,20 @@ fn test_serialize_rejects_adt_keys() { fn test_bytes_ser() { let buf = vec![]; let bytes = Bytes::new(&buf); - assert_eq!(to_string(&bytes).unwrap(), "[]".to_string()); + assert_eq!(to_string(&bytes).unwrap(), "[]".to_owned()); let buf = vec![1, 2, 3]; let bytes = Bytes::new(&buf); - assert_eq!(to_string(&bytes).unwrap(), "[1,2,3]".to_string()); + assert_eq!(to_string(&bytes).unwrap(), "[1,2,3]".to_owned()); } #[test] fn test_byte_buf_ser() { let bytes = ByteBuf::new(); - assert_eq!(to_string(&bytes).unwrap(), "[]".to_string()); + assert_eq!(to_string(&bytes).unwrap(), "[]".to_owned()); let bytes = ByteBuf::from(vec![1, 2, 3]); - assert_eq!(to_string(&bytes).unwrap(), "[1,2,3]".to_string()); + assert_eq!(to_string(&bytes).unwrap(), "[1,2,3]".to_owned()); } #[test]