Skip to content

Commit

Permalink
Replace str::to_string with to_owned
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 4, 2024
1 parent 3f4e30a commit d254281
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 95 deletions.
12 changes: 6 additions & 6 deletions src/value/from.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -85,7 +85,7 @@ impl From<String> 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 {
Expand All @@ -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())
}
}

Expand All @@ -126,7 +126,7 @@ impl<'a> From<Cow<'a, str>> for Value {
/// use serde_json::Value;
/// use std::borrow::Cow;
///
/// let s: Cow<str> = Cow::Owned("lorem".to_string());
/// let s: Cow<str> = Cow::Owned("lorem".to_owned());
/// let x: Value = s.into();
/// ```
fn from(f: Cow<'a, str>) -> Self {
Expand Down Expand Up @@ -159,7 +159,7 @@ impl From<Map<String, Value>> 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<String, Value>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion tests/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down
Loading

0 comments on commit d254281

Please sign in to comment.