mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 14:12:31 +00:00
Remove ErrorKind::BadExtension
This commit is contained in:
parent
19b46c6a96
commit
03b7384f8b
4 changed files with 8 additions and 34 deletions
|
@ -17,9 +17,7 @@ pub type Result<T> = std::result::Result<T, LoftyError>;
|
|||
#[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")
|
||||
},
|
||||
|
|
|
@ -126,7 +126,7 @@ impl Probe<BufReader<File>> {
|
|||
|
||||
Ok(Self {
|
||||
inner: BufReader::new(File::open(path)?),
|
||||
f_ty: FileType::from_path(path).ok(),
|
||||
f_ty: FileType::from_path(path),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<P>(path: P) -> Result<Self>
|
||||
/// Attempts to determine a [`FileType`] from a path
|
||||
pub fn from_path<P>(path: P) -> Option<Self>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Self, Self::Err>;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
/// Represents a parsed tag
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue