refactor after code review

This commit is contained in:
localthomas 2022-01-21 17:31:14 +01:00
parent 3783bfbbb8
commit 134d91d61a
2 changed files with 5 additions and 5 deletions

View file

@ -14,7 +14,10 @@ pub(crate) fn verify_frame_sync(frame_sync: [u8; 2]) -> bool {
/// Only the first match is returned and on no match, [`None`] is returned instead.
///
/// Note that the search searches in 8 bit steps, i.e. the first 8 bits need to be byte aligned.
pub(crate) fn search_for_frame_sync(input: &mut dyn Read) -> Result<Option<u64>> {
pub(crate) fn search_for_frame_sync<R>(input: &mut R) -> Result<Option<u64>>
where
R: Read,
{
let mut index = 0u64;
let mut iterator = input.bytes();
let mut buffer = [0u8; 2];

View file

@ -163,8 +163,6 @@ impl<R: Read + Seek> Probe<R> {
// estimate the file type by using these 36 bytes
// note that any error from `from_buffer_inner` are suppressed, as it returns an error on unknown format
// - TODO: why is the case `Err(LoftyError::UnknownFormat)` suppressed, but only for `from_buffer_inner`?
// - What is the special meaning of the return type `Ok(None)` vs `Err(LoftyError::UnknownFormat)`?
match FileType::from_buffer_inner(&buf[..buf_len]) {
// the file type was guessed based on these bytes
Ok((Some(f_ty), _)) => Ok(Some(f_ty)),
@ -295,8 +293,7 @@ mod tests {
];
let data: Vec<u8> = data.into_iter().flatten().cloned().collect();
let data = std::io::Cursor::new(&data);
let probe = Probe::new(data);
let probe = probe.guess_file_type().unwrap();
let probe = Probe::new(data).guess_file_type().unwrap();
matches!(probe.file_type(), Some(crate::FileType::MP3));
}
}