Skip to content

Commit

Permalink
Allow creating RawValues from references to unsized values
Browse files Browse the repository at this point in the history
  • Loading branch information
EFanZh committed Jan 1, 2022
1 parent 18a88da commit 012f567
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl From<Box<RawValue>> for Box<str> {
#[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))]
pub fn to_raw_value<T>(value: &T) -> Result<Box<RawValue>, Error>
where
T: Serialize,
T: Serialize + ?Sized,
{
let json_string = crate::to_string(value)?;
Ok(RawValue::from_owned(json_string.into_boxed_str()))
Expand Down
9 changes: 9 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,15 @@ fn test_raw_invalid_utf8() {
);
}

#[cfg(feature = "raw_value")]
#[test]
fn test_serialize_unsized_value_to_raw_value() {
assert_eq!(
serde_json::value::to_raw_value("foobar").unwrap().get(),
r#""foobar""#
);
}

#[test]
fn test_borrow_in_map_key() {
#[derive(Deserialize, Debug)]
Expand Down

0 comments on commit 012f567

Please sign in to comment.