Replace byte slices with str

This commit is contained in:
Brian Carroll 2022-05-22 19:25:39 +01:00
parent c16a5ad8ae
commit 84a3ac2ef6
No known key found for this signature in database
GPG key ID: 9CF4E3BF9C4722C7
7 changed files with 68 additions and 63 deletions

View file

@ -52,15 +52,15 @@ impl Parse<()> for u32 {
}
}
// Parse string bytes without utf8 validation
impl<'a> Parse<&'a Bump> for &'a [u8] {
impl<'a> Parse<&'a Bump> for &'a str {
fn parse(arena: &'a Bump, bytes: &[u8], cursor: &mut usize) -> Result<Self, ParseError> {
let len = u32::parse((), bytes, cursor)?;
let end = *cursor + len as usize;
let bytes: &[u8] = &bytes[*cursor..end];
let copy = arena.alloc_slice_copy(bytes);
let s = unsafe { std::str::from_utf8_unchecked(copy) };
*cursor = end;
Ok(copy)
Ok(s)
}
}