mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Replace byte slices with str
This commit is contained in:
parent
c16a5ad8ae
commit
84a3ac2ef6
7 changed files with 68 additions and 63 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue