Skip to content

Commit 6de3d39

Browse files
committed
Merge pull request 841 from EFanZh/unsized-value-to-raw-value
2 parents 18a88da + 012f567 commit 6de3d39

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/raw.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl From<Box<RawValue>> for Box<str> {
282282
#[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))]
283283
pub fn to_raw_value<T>(value: &T) -> Result<Box<RawValue>, Error>
284284
where
285-
T: Serialize,
285+
T: ?Sized + Serialize,
286286
{
287287
let json_string = crate::to_string(value)?;
288288
Ok(RawValue::from_owned(json_string.into_boxed_str()))

‎tests/test.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,15 @@ fn test_raw_invalid_utf8() {
22642264
);
22652265
}
22662266

2267+
#[cfg(feature = "raw_value")]
2268+
#[test]
2269+
fn test_serialize_unsized_value_to_raw_value() {
2270+
assert_eq!(
2271+
serde_json::value::to_raw_value("foobar").unwrap().get(),
2272+
r#""foobar""#,
2273+
);
2274+
}
2275+
22672276
#[test]
22682277
fn test_borrow_in_map_key() {
22692278
#[derive(Deserialize, Debug)]

0 commit comments

Comments
 (0)