pub struct Magic { /* private fields */ }Expand description
The content rules, in the order the database gives them.
Implementations§
Source§impl Magic
impl Magic
Sourcepub fn parse(bytes: &[u8]) -> Magic
pub fn parse(bytes: &[u8]) -> Magic
Parses one magic file.
A file that does not start with the header is not this format and is ignored rather than guessed at. Anything unparseable after that ends the read: the format is length-prefixed, so once a length is misread there is no way back to a known position — and a wrong guess about where the next rule starts is worse than stopping with what was understood.
Sourcepub fn load_from(dirs: &[PathBuf]) -> Magic
pub fn load_from(dirs: &[PathBuf]) -> Magic
Reads every magic file under the given directories. Later
directories add their sections after the earlier ones, which is
the order the priority sort then works over.
Sourcepub fn of_file(&self, path: &Path) -> Option<Match>
pub fn of_file(&self, path: &Path) -> Option<Match>
The best content match for a file, reading only its first
SNIFF_BYTES.
Sourcepub fn all_of_data(&self, data: &[u8]) -> Vec<Match>
pub fn all_of_data(&self, data: &[u8]) -> Vec<Match>
Every content match, best first — mimetype --all.
pub fn is_empty(&self) -> bool
Trait Implementations§
impl Eq for Magic
impl StructuralPartialEq for Magic
Auto Trait Implementations§
impl Freeze for Magic
impl RefUnwindSafe for Magic
impl Send for Magic
impl Sync for Magic
impl Unpin for Magic
impl UnsafeUnpin for Magic
impl UnwindSafe for Magic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more