From 134d91d61af9bd1376d1c881433a03cef6fea1e0 Mon Sep 17 00:00:00 2001 From: localthomas <81923579+localthomas@users.noreply.github.com> Date: Fri, 21 Jan 2022 17:31:14 +0100 Subject: [PATCH] refactor after code review --- src/mp3/header.rs | 5 ++++- src/probe.rs | 5 +---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mp3/header.rs b/src/mp3/header.rs index 9ee9701d..240881c6 100644 --- a/src/mp3/header.rs +++ b/src/mp3/header.rs @@ -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> { +pub(crate) fn search_for_frame_sync(input: &mut R) -> Result> +where + R: Read, +{ let mut index = 0u64; let mut iterator = input.bytes(); let mut buffer = [0u8; 2]; diff --git a/src/probe.rs b/src/probe.rs index 97883c20..dd99f950 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -163,8 +163,6 @@ impl Probe { // 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 = 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)); } }