serialize: Add ToJson impl for str
This commit is contained in:
parent
6f7081fad5
commit
0053fbb891
1 changed files with 6 additions and 1 deletions
|
@ -2315,6 +2315,10 @@ impl ToJson for bool {
|
||||||
fn to_json(&self) -> Json { Boolean(*self) }
|
fn to_json(&self) -> Json { Boolean(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToJson for str {
|
||||||
|
fn to_json(&self) -> Json { String(self.into_string()) }
|
||||||
|
}
|
||||||
|
|
||||||
impl ToJson for string::String {
|
impl ToJson for string::String {
|
||||||
fn to_json(&self) -> Json { String((*self).clone()) }
|
fn to_json(&self) -> Json { String((*self).clone()) }
|
||||||
}
|
}
|
||||||
|
@ -3714,7 +3718,8 @@ mod tests {
|
||||||
assert_eq!(f64::NAN.to_json(), Null);
|
assert_eq!(f64::NAN.to_json(), Null);
|
||||||
assert_eq!(true.to_json(), Boolean(true));
|
assert_eq!(true.to_json(), Boolean(true));
|
||||||
assert_eq!(false.to_json(), Boolean(false));
|
assert_eq!(false.to_json(), Boolean(false));
|
||||||
assert_eq!("abc".to_string().to_json(), String("abc".to_string()));
|
assert_eq!("abc".to_json(), String("abc".into_string()));
|
||||||
|
assert_eq!("abc".into_string().to_json(), String("abc".into_string()));
|
||||||
assert_eq!((1u, 2u).to_json(), list2);
|
assert_eq!((1u, 2u).to_json(), list2);
|
||||||
assert_eq!((1u, 2u, 3u).to_json(), list3);
|
assert_eq!((1u, 2u, 3u).to_json(), list3);
|
||||||
assert_eq!([1u, 2].to_json(), list2);
|
assert_eq!([1u, 2].to_json(), list2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue