Skip to main content

FileId

Struct FileId 

Source
pub struct FileId(/* private fields */);
Expand description

The identity of an existing file: device and inode on unix, volume serial number and file index on Windows.

Two ids are equal when the paths they were taken from name the same file: through a hard link, a symlink, a different case on a case-insensitive file system, or a relative and an absolute spelling.

A FileId holds an open handle to the file. On Windows the identity is valid only while that handle is open, so keep the FileId alive for as long as it is compared. Creating many ids at once holds many open files.

same-file compares a 32-bit volume serial number and a 64-bit file index, but ReFS (Dev Drive) file ids are 128 bits, so two different files could compare equal there. Two ids therefore also have to agree on the file length to be equal; a pair of different files of the same length on ReFS is the one case left undetected.

The length is read when two ids are compared, not when they are created (a growing temp file stays equal to itself). Two ids compare equal only if both lengths can be read and match, so an id is not necessarily equal to itself and the type is PartialEq only.

Implementations§

Source§

impl FileId

Source

pub fn of(path: &Path) -> Option<FileId>

The identity of the file at path (symlinks are followed), or None when it cannot be opened (missing, removed meanwhile, no permission) or is neither a regular file nor a folder (a FIFO or device is never opened). A file without an identity is never the same as another one.

Source§

impl FileId

Source

pub fn stdout() -> Option<FileId>

The identity of the file standard output is redirected to, or None unless that is a regular file: a terminal, a device, a closed stdout or a failed duplicate all give None.

The identity is taken from a duplicate of the stdout descriptor (handle on Windows), owned by the returned id, so dropping it never closes the process’s real stdout. On Windows a pipe or NUL may get an identity; a pipe lives on the named-pipe file system’s volume and never matches a file on a disk volume, so nothing is excluded (NUL is no disk file either, so an identity for it is harmless).

Trait Implementations§

Source§

impl Debug for FileId

Source§

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

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

impl PartialEq for FileId

Source§

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

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

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

Inequality operator !=. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.