From 03b7384f8b1a19077699f831d32133a676ac8e8e Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Thu, 17 Feb 2022 19:00:38 -0500 Subject: [PATCH] Remove `ErrorKind::BadExtension` --- src/error.rs | 7 +------ src/probe.rs | 2 +- src/types/file.rs | 27 ++++++--------------------- src/types/tag.rs | 6 ------ 4 files changed, 8 insertions(+), 34 deletions(-) diff --git a/src/error.rs b/src/error.rs index 44c1f6ef..15f434ef 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,9 +17,7 @@ pub type Result = std::result::Result; #[non_exhaustive] /// The types of errors that can occur pub enum ErrorKind { - // File extension/format related errors - /// Unsupported file extension - BadExtension(String), + // File format related errors /// Unable to guess the format UnknownFormat, @@ -358,9 +356,6 @@ impl Display for LoftyError { ErrorKind::Io(ref err) => write!(f, "{}", err), ErrorKind::Alloc(ref err) => write!(f, "{}", err), - ErrorKind::BadExtension(ref ext) => { - write!(f, "Found unknown file extension \"{}\"", ext) - }, ErrorKind::UnknownFormat => { write!(f, "No format could be determined from the provided file") }, diff --git a/src/probe.rs b/src/probe.rs index d84b7886..1a43d402 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -126,7 +126,7 @@ impl Probe> { Ok(Self { inner: BufReader::new(File::open(path)?), - f_ty: FileType::from_path(path).ok(), + f_ty: FileType::from_path(path), }) } } diff --git a/src/types/file.rs b/src/types/file.rs index 1c001453..1d5f1239 100644 --- a/src/types/file.rs +++ b/src/types/file.rs @@ -1,6 +1,6 @@ use super::properties::FileProperties; use super::tag::{Tag, TagIO, TagType}; -use crate::error::{ErrorKind, LoftyError, Result}; +use crate::error::Result; use std::convert::TryInto; use std::ffi::OsStr; @@ -271,28 +271,13 @@ impl FileType { } } - /// Attempts to extract a [`FileType`] from a path - /// - /// # Errors - /// - /// This will return [`ErrorKind::BadExtension`] if the extension didn't map to a `FileType` - pub fn from_path

(path: P) -> Result + /// Attempts to determine a [`FileType`] from a path + pub fn from_path

(path: P) -> Option where P: AsRef, { let ext = path.as_ref().extension(); - - ext.and_then(Self::from_ext).map_or_else( - || { - let ext_err = match ext { - Some(ext) => ext.to_string_lossy().into_owned(), - None => String::new(), - }; - - Err(LoftyError::new(ErrorKind::BadExtension(ext_err))) - }, - Ok, - ) + ext.and_then(Self::from_ext) } /// Attempts to extract a [`FileType`] from a buffer @@ -365,9 +350,9 @@ impl FileType { 79 if buf.len() >= 36 && &buf[..4] == b"OggS" => { if &buf[29..35] == b"vorbis" { return Some(Self::Vorbis); - } else if &buf[28..] == b"OpusHead" { + } else if &buf[28..36] == b"OpusHead" { return Some(Self::Opus); - } else if &buf[28..] == b"Speex " { + } else if &buf[28..36] == b"Speex " { return Some(Self::Speex); } diff --git a/src/types/tag.rs b/src/types/tag.rs index 6ed0673f..64352c41 100644 --- a/src/types/tag.rs +++ b/src/types/tag.rs @@ -104,12 +104,6 @@ pub trait TagIO: Accessor + Sized { fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err>; } -pub(crate) trait ParsableTag: Sized { - type Err; - - fn parse() -> std::result::Result; -} - #[derive(Clone)] /// Represents a parsed tag ///