Struct filetime::FileTime

source ·
pub struct FileTime { /* private fields */ }
Expand description

A helper structure to represent a timestamp for a file.

The actual value contined within is platform-specific and does not have the same meaning across platforms, but comparisons and stringification can be significant among the same platform.

Implementations§

source§

impl FileTime

source

pub const fn zero() -> FileTime

Creates a new timestamp representing a 0 time.

Useful for creating the base of a cmp::max chain of times.

source

pub fn now() -> FileTime

Creates a new timestamp representing the current system time.

filetime::set_file_mtime(path, FileTime::now())?;

Equivalent to FileTime::from_system_time(SystemTime::now()).

source

pub const fn from_unix_time(seconds: i64, nanos: u32) -> FileTime

Creates a new instance of FileTime with a number of seconds and nanoseconds relative to the Unix epoch, 1970-01-01T00:00:00Z.

Negative seconds represent times before the Unix epoch, and positive values represent times after it. Nanos always count forwards in time.

Note that this is typically the relative point that Unix time stamps are from, but on Windows the native time stamp is relative to January 1, 1601 so the return value of seconds from the returned FileTime instance may not be the same as that passed in.

source

pub fn from_last_modification_time(meta: &Metadata) -> FileTime

Creates a new timestamp from the last modification time listed in the specified metadata.

The returned value corresponds to the mtime field of stat on Unix platforms and the ftLastWriteTime field on Windows platforms.

source

pub fn from_last_access_time(meta: &Metadata) -> FileTime

Creates a new timestamp from the last access time listed in the specified metadata.

The returned value corresponds to the atime field of stat on Unix platforms and the ftLastAccessTime field on Windows platforms.

source

pub fn from_creation_time(meta: &Metadata) -> Option<FileTime>

Creates a new timestamp from the creation time listed in the specified metadata.

The returned value corresponds to the birthtime field of stat on Unix platforms and the ftCreationTime field on Windows platforms. Note that not all Unix platforms have this field available and may return None in some circumstances.

source

pub fn from_system_time(time: SystemTime) -> FileTime

Creates a new timestamp from the given SystemTime.

Windows counts file times since 1601-01-01T00:00:00Z, and cannot represent times before this, but it’s possible to create a SystemTime that does. This function will error if passed such a SystemTime.

source

pub const fn seconds(&self) -> i64

Returns the whole number of seconds represented by this timestamp.

Note that this value’s meaning is platform specific. On Unix platform time stamps are typically relative to January 1, 1970, but on Windows platforms time stamps are relative to January 1, 1601.

source

pub const fn unix_seconds(&self) -> i64

Returns the whole number of seconds represented by this timestamp, relative to the Unix epoch start of January 1, 1970.

Note that this does not return the same value as seconds for Windows platforms as seconds are relative to a different date there.

source

pub const fn nanoseconds(&self) -> u32

Returns the nanosecond precision of this timestamp.

The returned value is always less than one billion and represents a portion of a second forward from the seconds returned by the seconds method.

Trait Implementations§

source§

impl Clone for FileTime

source§

fn clone(&self) -> FileTime

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for FileTime

source§

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

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

impl Display for FileTime

source§

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

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

impl From<SystemTime> for FileTime

source§

fn from(time: SystemTime) -> FileTime

Converts to this type from the input type.
source§

impl Hash for FileTime

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 Ord for FileTime

source§

fn cmp(&self, other: &FileTime) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<FileTime> for FileTime

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<FileTime> for FileTime

source§

fn partial_cmp(&self, other: &FileTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for FileTime

source§

impl Eq for FileTime

source§

impl StructuralEq for FileTime

source§

impl StructuralPartialEq for FileTime

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.