[−][src]Struct infer::Infer
Infer allows to use a custom set of Matcher
s for infering a MIME type.
Most operations can be done by using the top level functions, but when custom matchers
are needed every call has to go through the Infer
struct to be able
to see the custom matchers.
Implementations
impl Infer
[src]
pub const fn new() -> Infer
[src]
Initialize a new instance of the infer struct.
pub fn get(&self, buf: &[u8]) -> Option<Type>
[src]
Returns the file type of the buffer.
Examples
let info = infer::Infer::new(); let buf = [0xFF, 0xD8, 0xFF, 0xAA]; let kind = info.get(&buf).expect("file type is known"); assert_eq!(kind.mime_type(), "image/jpeg"); assert_eq!(kind.extension(), "jpg");
pub fn get_from_path<P: AsRef<Path>>(&self, path: P) -> Result<Option<Type>>
[src]
pub fn is(&self, buf: &[u8], extension: &str) -> bool
[src]
pub fn is_mime(&self, buf: &[u8], mime_type: &str) -> bool
[src]
pub fn is_supported(&self, extension: &str) -> bool
[src]
pub fn is_mime_supported(&self, mime_type: &str) -> bool
[src]
pub fn is_app(&self, buf: &[u8]) -> bool
[src]
pub fn is_archive(&self, buf: &[u8]) -> bool
[src]
pub fn is_audio(&self, buf: &[u8]) -> bool
[src]
pub fn is_document(&self, buf: &[u8]) -> bool
[src]
pub fn is_font(&self, buf: &[u8]) -> bool
[src]
pub fn is_image(&self, buf: &[u8]) -> bool
[src]
pub fn is_video(&self, buf: &[u8]) -> bool
[src]
pub fn is_custom(&self, buf: &[u8]) -> bool
[src]
Determines whether a buffer is one of the custom types added.
Examples
fn custom_matcher(buf: &[u8]) -> bool { return buf.len() >= 3 && buf[0] == 0x10 && buf[1] == 0x11 && buf[2] == 0x12; } let mut info = infer::Infer::new(); info.add("custom/foo", "foo", custom_matcher); let buf = [0x10, 0x11, 0x12, 0x13]; assert!(info.is_custom(&buf));
pub fn add(
&mut self,
mime_type: &'static str,
extension: &'static str,
m: Matcher
)
[src]
&mut self,
mime_type: &'static str,
extension: &'static str,
m: Matcher
)
Adds a custom matcher.
Custom matchers are matched in order of addition and before the default set of matchers.
Examples
fn custom_matcher(buf: &[u8]) -> bool { return buf.len() >= 3 && buf[0] == 0x10 && buf[1] == 0x11 && buf[2] == 0x12; } let mut info = infer::Infer::new(); info.add("custom/foo", "foo", custom_matcher); let buf = [0x10, 0x11, 0x12, 0x13]; let kind = info.get(&buf).expect("file type is known"); assert_eq!(kind.mime_type(), "custom/foo"); assert_eq!(kind.extension(), "foo");
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Infer
impl Send for Infer
impl Sync for Infer
impl Unpin for Infer
impl UnwindSafe for Infer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,