Skip to content

Commit

Permalink
Using manual implementation of <[u8]>::split_first_chunk::<4>
Browse files Browse the repository at this point in the history
  • Loading branch information
sammhicks committed Jul 24, 2024
1 parent ba04b10 commit 4c6de3d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,17 @@ impl<'a, 'de, 's> de::Deserializer<'de> for &'a mut Deserializer<'de, 's> {
Some(b'r') => b'\r',
Some(b't') => b'\t',
Some(b'u') => {
// TODO - Replace with `<[u8]>::split_first_chunk::<4>` once MSRV >= 1.77
fn split_first_slice(
bytes: &[u8],
len: usize,
) -> Option<(&[u8], &[u8])>
{
Some((bytes.get(..len)?, bytes.get(len..)?))
}

let (escape_sequence, remaining_escaped_string_bytes) =
escaped_string_bytes
.as_slice()
.split_first_chunk::<4>()
split_first_slice(escaped_string_bytes.as_slice(), 4)
.ok_or(Error::InvalidEscapeSequence)?;

escaped_string_bytes =
Expand Down

0 comments on commit 4c6de3d

Please sign in to comment.