Skip to content

Commit 0053fbb

Browse files
committed
serialize: Add ToJson impl for str
1 parent 6f7081f commit 0053fbb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/libserialize/json.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,10 @@ impl ToJson for bool {
23152315
fn to_json(&self) -> Json { Boolean(*self) }
23162316
}
23172317

2318+
impl ToJson for str {
2319+
fn to_json(&self) -> Json { String(self.into_string()) }
2320+
}
2321+
23182322
impl ToJson for string::String {
23192323
fn to_json(&self) -> Json { String((*self).clone()) }
23202324
}
@@ -3714,7 +3718,8 @@ mod tests {
37143718
assert_eq!(f64::NAN.to_json(), Null);
37153719
assert_eq!(true.to_json(), Boolean(true));
37163720
assert_eq!(false.to_json(), Boolean(false));
3717-
assert_eq!("abc".to_string().to_json(), String("abc".to_string()));
3721+
assert_eq!("abc".to_json(), String("abc".into_string()));
3722+
assert_eq!("abc".into_string().to_json(), String("abc".into_string()));
37183723
assert_eq!((1u, 2u).to_json(), list2);
37193724
assert_eq!((1u, 2u, 3u).to_json(), list3);
37203725
assert_eq!([1u, 2].to_json(), list2);

0 commit comments

Comments
 (0)