Skip to main content

Meta

Struct Meta 

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

What identification needs to know about a path besides its name: its FileKind and whether it is executable.

Build it from fs::Metadata (Meta::from_metadata), from a git index mode without any system call (Meta::from_git_mode), or by hand.

Implementations§

Source§

impl Meta

Source

pub const fn new(kind: FileKind, executable: bool) -> Self

A meta with the given kind and executable flag.

Source

pub const fn regular(executable: bool) -> Self

A regular file.

Source

pub const fn kind(self) -> FileKind

The entry kind.

Source

pub const fn is_executable(self) -> bool

Whether the entry is executable (only meaningful for regular files and FileKind::Other).

Source

pub const fn with_executable(self, executable: bool) -> Self

The same meta with a different executable flag.

Source

pub fn from_metadata(metadata: &Metadata, policy: ExecPolicy) -> Self

From lstat metadata (fs::symlink_metadata); executability is decided by policy for regular files and FileKind::Other.

Source

pub const fn from_git_mode(mode: u32) -> Option<Self>

From a git index / tree mode, with git’s own executable bit:

modemeta
100644 (any 100xxx without the owner x bit)regular file
100755 (any 100xxx with the owner x bit)executable regular file
120000symlink
160000 (gitlink / submodule), 040000 (tree)directory
anything elseNone

This needs no system call. It matches what identify would see on a checkout where the work tree agrees with the index (e.g. after pre-commit stashed unstaged changes) on Unix with core.fileMode=true and core.symlinks=true. On Windows identify considers every file executable; use Meta::from_git_mode_with with ExecPolicy::PythonCompat to reproduce that.

120000 says the index holds a symlink. With core.symlinks=false (the usual configuration on Windows, and set automatically on file systems without symlinks) git checks it out as a regular file that contains the target path, which identify tags file, text and executable on Windows. On Windows, or whenever core.symlinks is false, lstat such entries instead (tags_from_path or tags_from_metadata).

use file_identify::{FileKind, Meta};

assert_eq!(Meta::from_git_mode(0o100755), Some(Meta::regular(true)));
assert_eq!(Meta::from_git_mode(0o120000).map(Meta::kind), Some(FileKind::Symlink));
assert_eq!(Meta::from_git_mode(0), None);
Source

pub fn from_git_mode_with(mode: u32, policy: ExecPolicy) -> Option<Self>

Like Meta::from_git_mode, with platform executable semantics: ExecPolicy::PythonCompat on Windows marks every regular file executable (as identify does); otherwise git’s bit is used.

A 120000 entry still gives FileKind::Symlink: on Windows a checkout usually has a regular file there (core.symlinks=false), so lstat those entries instead; see Meta::from_git_mode.

Trait Implementations§

Source§

impl Clone for Meta

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Meta

Source§

impl Debug for Meta

Source§

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

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

impl Eq for Meta

Source§

impl Hash for Meta

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Meta

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Meta

Auto Trait Implementations§

§

impl Freeze for Meta

§

impl RefUnwindSafe for Meta

§

impl Send for Meta

§

impl Sync for Meta

§

impl Unpin for Meta

§

impl UnsafeUnpin for Meta

§

impl UnwindSafe for Meta

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.