Enum lofty::FileType

source ·
#[non_exhaustive]
pub enum FileType {
Show 13 variants Aac, Aiff, Ape, Flac, Mpeg, Mp4, Mpc, Opus, Vorbis, Speex, Wav, WavPack, Custom(&'static str),
}
Expand description

The type of file read

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Aac

§

Aiff

§

Ape

§

Flac

§

Mpeg

§

Mp4

§

Mpc

§

Opus

§

Vorbis

§

Speex

§

Wav

§

WavPack

§

Custom(&'static str)

Implementations§

source§

impl FileType

source

pub fn primary_tag_type(&self) -> TagType

Returns the file type’s “primary” TagType, or the one most likely to be used in the target format

FileTypeTagType
Aac, Aiff, Mp3, WavId3v2
Ape , Mpc, WavPackApe
Flac, Opus, Vorbis, SpeexVorbisComments
Mp4Mp4Ilst
§Panics

If an unregistered FileType (FileType::Custom) is encountered. See register_custom_resolver.

§Examples
use lofty::{FileType, TagType};

let file_type = FileType::Mpeg;
assert_eq!(file_type.primary_tag_type(), TagType::Id3v2);
source

pub fn supports_tag_type(&self, tag_type: TagType) -> bool

Returns if the target FileType supports a TagType

NOTE: This is feature dependent, meaning if you do not have the id3v2 feature enabled, FileType::Mpeg will return false for TagType::Id3v2.

§Panics

If an unregistered FileType (FileType::Custom) is encountered. See register_custom_resolver.

§Examples
use lofty::{FileType, TagType};

let file_type = FileType::Mpeg;
assert!(file_type.supports_tag_type(TagType::Id3v2));
source

pub fn from_ext<E>(ext: E) -> Option<Self>
where E: AsRef<OsStr>,

Attempts to extract a FileType from an extension

§Examples
use lofty::FileType;

let extension = "mp3";
assert_eq!(FileType::from_ext(extension), Some(FileType::Mpeg));
source

pub fn from_path<P>(path: P) -> Option<Self>
where P: AsRef<Path>,

Attempts to determine a FileType from a path

§Examples
use lofty::FileType;
use std::path::Path;

let path = Path::new("path/to/my.mp3");
assert_eq!(FileType::from_path(path), Some(FileType::Mpeg));
source

pub fn from_buffer(buf: &[u8]) -> Option<Self>

Attempts to extract a FileType from a buffer

NOTES:

§Examples
use lofty::FileType;
use std::fs::File;
use std::io::Read;

let mut file = File::open(path_to_opus)?;

let mut buf = [0; 50]; // Search the first 50 bytes of the file
file.read_exact(&mut buf)?;

assert_eq!(FileType::from_buffer(&buf), Some(FileType::Opus));

Trait Implementations§

source§

impl Clone for FileType

source§

fn clone(&self) -> FileType

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FileType

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for FileType

source§

fn eq(&self, other: &FileType) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for FileType

source§

impl Eq for FileType

source§

impl StructuralEq for FileType

source§

impl StructuralPartialEq for FileType

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.