Skip to content

Commit 683832a

Browse files
committed
Touch up doc changes from PR 828
1 parent 691466c commit 683832a

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/de.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,8 @@ impl<'de, 'a, R: Read<'de>> de::Deserializer<'de> for &'a mut Deserializer<R> {
15601560
///
15611561
/// # Examples
15621562
///
1563-
/// You can use this to parse JSON strings containing invalid UTF-8 bytes.
1563+
/// You can use this to parse JSON strings containing invalid UTF-8 bytes,
1564+
/// or unpaired surrogates.
15641565
///
15651566
/// ```
15661567
/// use serde_bytes::ByteBuf;
@@ -1580,21 +1581,18 @@ impl<'de, 'a, R: Read<'de>> de::Deserializer<'de> for &'a mut Deserializer<R> {
15801581
/// ```
15811582
///
15821583
/// Backslash escape sequences like `\n` are still interpreted and required
1583-
/// to be valid. `\u` escape sequences are required to represent valid
1584-
/// Unicode code points, except in the case of lone surrogates.
1584+
/// to be valid. `\u` escape sequences are required to represent a valid
1585+
/// Unicode code point or lone surrogate.
15851586
///
15861587
/// ```
15871588
/// use serde_bytes::ByteBuf;
15881589
///
1589-
/// fn look_at_bytes() {
1590+
/// fn look_at_bytes() -> Result<(), serde_json::Error> {
15901591
/// let json_data = b"\"lone surrogate: \\uD801\"";
1591-
/// let parsed: Result<ByteBuf, _> = serde_json::from_slice(json_data);
1592-
///
1593-
/// assert!(parsed.is_ok());
1594-
///
1592+
/// let bytes: ByteBuf = serde_json::from_slice(json_data)?;
15951593
/// let expected = b"lone surrogate: \xED\xA0\x81";
1596-
/// let bytes: ByteBuf = parsed.unwrap();
1597-
/// assert_eq!(expected, &bytes[..]);
1594+
/// assert_eq!(expected, bytes.as_slice());
1595+
/// Ok(())
15981596
/// }
15991597
/// #
16001598
/// # look_at_bytes();

src/read.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,10 @@ fn parse_escape<'de, R: Read<'de>>(
875875
return Ok(());
876876
}
877877

878-
// Non-BMP characters are encoded as a sequence of
879-
// two hex escapes, representing UTF-16 surrogates.
880-
// If `validate` is false and we only find a single
881-
// hex escape that is a surrogate, then we'll accept
882-
// it instead of erroring.
878+
// Non-BMP characters are encoded as a sequence of two hex
879+
// escapes, representing UTF-16 surrogates. If deserializing a
880+
// utf-8 string the surrogates are required to be paired,
881+
// whereas deserializing a byte string accepts lone surrogates.
883882
n1 @ 0xD800..=0xDBFF => {
884883
if tri!(peek_or_eof(read)) != b'\\' {
885884
if validate {

0 commit comments

Comments
 (0)