Struct Magic

Source
pub struct Magic { /* private fields */ }
Expand description

Configuration of which Flags and magic databases to use

Implementations§

Source§

impl Magic

Source

pub fn error(&self) -> Option<String>

Returns a textual explanation of the last error, if any

You should not need to call this, since you can use the FileMagicError in the Result returned by the other functions.

Source

pub fn file<P: AsRef<Path>>( &self, filename: P, ) -> Result<String, FileMagicError>

Returns a textual description of the contents of the filename

Source

pub fn buffer(&self, buffer: &[u8]) -> Result<String, FileMagicError>

Returns a textual description of the contents of the buffer

Source

pub fn check<P: AsRef<Path>>( &self, filenames: &[P], ) -> Result<(), FileMagicError>

Check the validity of entries in the database filenames

Source

pub fn compile<P: AsRef<Path>>( &self, filenames: &[P], ) -> Result<(), FileMagicError>

Compiles the given database filenames for faster access

The compiled files created are named from the basename of each file argument with ‘.mgc’ appended to it.

Source

pub fn list<P: AsRef<Path>>( &self, filenames: &[P], ) -> Result<(), FileMagicError>

Dumps all magic entries in the given database filenames in a human readable format

Source

pub fn set_flags(&self, flags: Flags) -> bool

Sets the flags to use

Overwrites any previously set flags, e.g. those from load().

Source

pub fn open(flags: Flags) -> Result<Magic, FileMagicError>

Creates a new configuration, flags specify how other functions should behave

This does not load() any databases yet.

Source

pub fn load<P: AsRef<Path>>( &self, magic_databases: &[P], ) -> Result<(), FileMagicError>

Loads the given database filenames for further queries Adds ‘.mgc’ to the database files as appropriate.

Trait Implementations§

Source§

impl Drop for Magic

Source§

fn drop(&mut self)

Closes the magic database and deallocates any resources used

Auto Trait Implementations§

§

impl Freeze for Magic

§

impl RefUnwindSafe for Magic

§

impl !Send for Magic

§

impl !Sync for Magic

§

impl Unpin for Magic

§

impl UnwindSafe for Magic

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.