Skip to content

Commit

Permalink
♻️ use [T]::split_at
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Oct 16, 2024
1 parent 4ea042c commit 653fa0b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lib/src/archive/read/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use std::borrow::Cow;
use std::io;

fn read_header_from_slice(bytes: &[u8]) -> io::Result<&[u8]> {
let (header, body) = bytes
.split_at_checked(PNA_HEADER.len())
.ok_or(io::ErrorKind::UnexpectedEof)?;
// TODO: use split_at_checked instead
let (header, body) = bytes.split_at(PNA_HEADER.len());
if header != PNA_HEADER {
return Err(io::Error::new(io::ErrorKind::InvalidData, "It's not PNA"));
}
Expand Down
5 changes: 2 additions & 3 deletions lib/src/chunk/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ pub(crate) fn read_chunk_from_slice(bytes: &[u8]) -> io::Result<(RawChunk<&[u8]>
crc_hasher.update(&ty[..]);

// read chunk data
let (data, r) = r
.split_at_checked(length as usize)
.ok_or(io::ErrorKind::UnexpectedEof)?;
// TODO: use split_at_checked instead
let (data, r) = r.split_at(length as usize);
crc_hasher.update(data);

// read crc sum
Expand Down

0 comments on commit 653fa0b

Please sign in to comment.