Movatterモバイル変換


[0]ホーム

URL:


std::fs

StructMetadata

1.0.0 ·Source
pub struct Metadata(/* private fields */);
Expand description

Metadata information about a file.

This structure is returned from themetadata orsymlink_metadata function or method and represents knownmetadata about a file such as its permissions, size, modificationtimes, etc.

Implementations§

Source§

implMetadata

1.1.0 ·Source

pub fnfile_type(&self) ->FileType

Returns the file type for this metadata.

§Examples
fnmain() -> std::io::Result<()> {usestd::fs;letmetadata = fs::metadata("foo.txt")?;println!("{:?}", metadata.file_type());Ok(())}
1.0.0 ·Source

pub fnis_dir(&self) ->bool

Returnstrue if this metadata is for a directory. Theresult is mutually exclusive to the result ofMetadata::is_file, and will be false for symlink metadataobtained fromsymlink_metadata.

§Examples
fnmain() -> std::io::Result<()> {usestd::fs;letmetadata = fs::metadata("foo.txt")?;assert!(!metadata.is_dir());Ok(())}
1.0.0 ·Source

pub fnis_file(&self) ->bool

Returnstrue if this metadata is for a regular file. Theresult is mutually exclusive to the result ofMetadata::is_dir, and will be false for symlink metadataobtained fromsymlink_metadata.

When the goal is simply to read from (or write to) the source, the mostreliable way to test the source can be read (or written to) is to openit. Only usingis_file can break workflows likediff <( prog_a ) ona Unix-like system for example. SeeFile::open orOpenOptions::open for more information.

§Examples
usestd::fs;fnmain() -> std::io::Result<()> {letmetadata = fs::metadata("foo.txt")?;assert!(metadata.is_file());Ok(())}
1.58.0 ·Source

pub fnis_symlink(&self) ->bool

Returnstrue if this metadata is for a symbolic link.

§Examples
usestd::fs;usestd::path::Path;usestd::os::unix::fs::symlink;fnmain() -> std::io::Result<()> {letlink_path = Path::new("link");    symlink("/origin_does_not_exist/", link_path)?;letmetadata = fs::symlink_metadata(link_path)?;assert!(metadata.is_symlink());Ok(())}
1.0.0 ·Source

pub fnlen(&self) ->u64

Returns the size of the file, in bytes, this metadata is for.

§Examples
usestd::fs;fnmain() -> std::io::Result<()> {letmetadata = fs::metadata("foo.txt")?;assert_eq!(0, metadata.len());Ok(())}
1.0.0 ·Source

pub fnpermissions(&self) ->Permissions

Returns the permissions of the file this metadata is for.

§Examples
usestd::fs;fnmain() -> std::io::Result<()> {letmetadata = fs::metadata("foo.txt")?;assert!(!metadata.permissions().readonly());Ok(())}
1.10.0 ·Source

pub fnmodified(&self) ->Result<SystemTime>

Returns the last modification time listed in this metadata.

The returned value corresponds to themtime field ofstat on Unixplatforms and theftLastWriteTime field on Windows platforms.

§Errors

This field might not be available on all platforms, and will return anErr on platforms where it is not available.

§Examples
usestd::fs;fnmain() -> std::io::Result<()> {letmetadata = fs::metadata("foo.txt")?;if letOk(time) = metadata.modified() {println!("{time:?}");    }else{println!("Not supported on this platform");    }Ok(())}
1.10.0 ·Source

pub fnaccessed(&self) ->Result<SystemTime>

Returns the last access time of this metadata.

The returned value corresponds to theatime field ofstat on Unixplatforms and theftLastAccessTime field on Windows platforms.

Note that not all platforms will keep this field update in a file’smetadata, for example Windows has an option to disable updating thistime when files are accessed and Linux similarly hasnoatime.

§Errors

This field might not be available on all platforms, and will return anErr on platforms where it is not available.

§Examples
usestd::fs;fnmain() -> std::io::Result<()> {letmetadata = fs::metadata("foo.txt")?;if letOk(time) = metadata.accessed() {println!("{time:?}");    }else{println!("Not supported on this platform");    }Ok(())}
1.10.0 ·Source

pub fncreated(&self) ->Result<SystemTime>

Returns the creation time listed in this metadata.

The returned value corresponds to thebtime field ofstatx onLinux kernel starting from to 4.11, thebirthtime field ofstat on otherUnix platforms, and theftCreationTime field on Windows platforms.

§Errors

This field might not be available on all platforms, and will return anErr on platforms or filesystems where it is not available.

§Examples
usestd::fs;fnmain() -> std::io::Result<()> {letmetadata = fs::metadata("foo.txt")?;if letOk(time) = metadata.created() {println!("{time:?}");    }else{println!("Not supported on this platform or filesystem");    }Ok(())}

Trait Implementations§

1.0.0 ·Source§

implClone forMetadata

Source§

fnclone(&self) ->Metadata

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

fnclone_from(&mut self, source: &Self)

Performs copy-assignment fromsource.Read more
1.16.0 ·Source§

implDebug forMetadata

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result

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

implMetadataExt forMetadata

Available onApple only.
Source§

fnas_raw_stat(&self) -> &stat

👎Deprecated since 1.8.0: deprecated in favor of the accessor methods of this trait
Available onmacOS or iOS only.
Gain a reference to the underlyingstat structure which containsthe raw information returned by the OS.Read more
Source§

fnst_dev(&self) ->u64

Source§

fnst_ino(&self) ->u64

Source§

fnst_mode(&self) ->u32

Source§

fnst_nlink(&self) ->u64

Source§

fnst_uid(&self) ->u32

Source§

fnst_gid(&self) ->u32

Source§

fnst_rdev(&self) ->u64

Source§

fnst_size(&self) ->u64

Source§

fnst_atime(&self) ->i64

Source§

fnst_atime_nsec(&self) ->i64

Source§

fnst_mtime(&self) ->i64

Source§

fnst_mtime_nsec(&self) ->i64

Source§

fnst_ctime(&self) ->i64

Source§

fnst_ctime_nsec(&self) ->i64

Source§

fnst_birthtime(&self) ->i64

Source§

fnst_birthtime_nsec(&self) ->i64

Source§

fnst_blksize(&self) ->u64

Source§

fnst_blocks(&self) ->u64

Source§

fnst_gen(&self) ->u32

Source§

fnst_flags(&self) ->u32

Source§

fnst_lspare(&self) ->u32

1.1.0 ·Source§

implMetadataExt forMetadata

Available onUnix only.
Source§

fndev(&self) ->u64

Returns the ID of the device containing the file.Read more
Source§

fnino(&self) ->u64

Returns the inode number.Read more
Source§

fnmode(&self) ->u32

Returns the rights applied to this file.Read more
Source§

fnnlink(&self) ->u64

Returns the number of hard links pointing to this file.Read more
Source§

fnuid(&self) ->u32

Returns the user ID of the owner of this file.Read more
Source§

fngid(&self) ->u32

Returns the group ID of the owner of this file.Read more
Source§

fnrdev(&self) ->u64

Returns the device ID of this file (if it is a special one).Read more
Source§

fnsize(&self) ->u64

Returns the total size of this file in bytes.Read more
Source§

fnatime(&self) ->i64

Returns the last access time of the file, in seconds since Unix Epoch.Read more
Source§

fnatime_nsec(&self) ->i64

Returns the last access time of the file, in nanoseconds sinceatime.Read more
Source§

fnmtime(&self) ->i64

Returns the last modification time of the file, in seconds since Unix Epoch.Read more
Source§

fnmtime_nsec(&self) ->i64

Returns the last modification time of the file, in nanoseconds sincemtime.Read more
Source§

fnctime(&self) ->i64

Returns the last status change time of the file, in seconds since Unix Epoch.Read more
Source§

fnctime_nsec(&self) ->i64

Returns the last status change time of the file, in nanoseconds sincectime.Read more
Source§

fnblksize(&self) ->u64

Returns the block size for filesystem I/O.Read more
Source§

fnblocks(&self) ->u64

Returns the number of blocks allocated to the file, in 512-byte units.Read more
1.1.0 ·Source§

implMetadataExt forMetadata

Available onLinux only.
Source§

fnas_raw_stat(&self) -> &stat

👎Deprecated since 1.8.0: other methods of this trait are now preferred
Gain a reference to the underlyingstat structure which containsthe raw information returned by the OS.Read more
Source§

fnst_dev(&self) ->u64

Returns the device ID on which this file resides.Read more
Source§

fnst_ino(&self) ->u64

Returns the inode number.Read more
Source§

fnst_mode(&self) ->u32

Returns the file type and mode.Read more
Source§

fnst_nlink(&self) ->u64

Returns the number of hard links to file.Read more
Source§

fnst_uid(&self) ->u32

Returns the user ID of the file owner.Read more
Source§

fnst_gid(&self) ->u32

Returns the group ID of the file owner.Read more
Source§

fnst_rdev(&self) ->u64

Returns the device ID that this file represents. Only relevant for special file.Read more
Source§

fnst_size(&self) ->u64

Returns the size of the file (if it is a regular file or a symbolic link) in bytes.Read more
Source§

fnst_atime(&self) ->i64

Returns the last access time of the file, in seconds since Unix Epoch.Read more
Source§

fnst_atime_nsec(&self) ->i64

Returns the last access time of the file, in nanoseconds sincest_atime.Read more
Source§

fnst_mtime(&self) ->i64

Returns the last modification time of the file, in seconds since Unix Epoch.Read more
Source§

fnst_mtime_nsec(&self) ->i64

Returns the last modification time of the file, in nanoseconds sincest_mtime.Read more
Source§

fnst_ctime(&self) ->i64

Returns the last status change time of the file, in seconds since Unix Epoch.Read more
Source§

fnst_ctime_nsec(&self) ->i64

Returns the last status change time of the file, in nanoseconds sincest_ctime.Read more
Source§

fnst_blksize(&self) ->u64

Returns the “preferred” block size for efficient filesystem I/O.Read more
Source§

fnst_blocks(&self) ->u64

Returns the number of blocks allocated to the file, 512-byte units.Read more
Source§

implMetadataExt forMetadata

Available onWASI only.
Source§

fndev(&self) ->u64

🔬This is a nightly-only experimental API. (wasi_ext #71213)
Returns thest_dev field of the internalfilestat_t
Source§

fnino(&self) ->u64

🔬This is a nightly-only experimental API. (wasi_ext #71213)
Returns thest_ino field of the internalfilestat_t
Source§

fnnlink(&self) ->u64

🔬This is a nightly-only experimental API. (wasi_ext #71213)
Returns thest_nlink field of the internalfilestat_t
Source§

fnsize(&self) ->u64

🔬This is a nightly-only experimental API. (wasi_ext #71213)
Returns thest_size field of the internalfilestat_t
Source§

fnatim(&self) ->u64

🔬This is a nightly-only experimental API. (wasi_ext #71213)
Returns thest_atim field of the internalfilestat_t
Source§

fnmtim(&self) ->u64

🔬This is a nightly-only experimental API. (wasi_ext #71213)
Returns thest_mtim field of the internalfilestat_t
Source§

fnctim(&self) ->u64

🔬This is a nightly-only experimental API. (wasi_ext #71213)
Returns thest_ctim field of the internalfilestat_t
1.1.0 ·Source§

implMetadataExt forMetadata

Available onWindows only.
Source§

fnfile_attributes(&self) ->u32

Returns the value of thedwFileAttributes field of this metadata.Read more
Source§

fncreation_time(&self) ->u64

Returns the value of theftCreationTime field of this metadata.Read more
Source§

fnlast_access_time(&self) ->u64

Returns the value of theftLastAccessTime field of this metadata.Read more
Source§

fnlast_write_time(&self) ->u64

Returns the value of theftLastWriteTime field of this metadata.Read more
Source§

fnfile_size(&self) ->u64

Returns the value of thenFileSize fields of thismetadata.Read more
Source§

fnvolume_serial_number(&self) ->Option<u32>

🔬This is a nightly-only experimental API. (windows_by_handle #63010)
Returns the value of thedwVolumeSerialNumber field of thismetadata.Read more
Source§

fnnumber_of_links(&self) ->Option<u32>

🔬This is a nightly-only experimental API. (windows_by_handle #63010)
Returns the value of thenNumberOfLinks field of thismetadata.Read more
Source§

fnfile_index(&self) ->Option<u64>

🔬This is a nightly-only experimental API. (windows_by_handle #63010)
Returns the value of thenFileIndex fields of thismetadata.Read more
Source§

fnchange_time(&self) ->Option<u64>

🔬This is a nightly-only experimental API. (windows_change_time #121478)
Returns the value of theChangeTime fields of this metadata.Read more

Auto Trait Implementations§

§

implFreeze forMetadata

§

implRefUnwindSafe forMetadata

§

implSend forMetadata

§

implSync forMetadata

§

implUnpin forMetadata

§

implUnwindSafe forMetadata

Blanket Implementations§

Source§

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

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

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

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

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

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T>CloneToUninit for T
where T:Clone,

Source§

unsafe fnclone_to_uninit(&self, dest:*mutu8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment fromself todest.Read more
Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fninto(self) -> U

CallsU::from(self).

That is, this conversion is whatever the implementation ofFrom<T> for U chooses to do.

Source§

impl<T>ToOwned for T
where T:Clone,

Source§

typeOwned = T

The resulting type after obtaining ownership.
Source§

fnto_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning.Read more
Source§

fnclone_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§

typeError =Infallible

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

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

typeError = <U asTryFrom<T>>::Error

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

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.

[8]ページ先頭

©2009-2025 Movatter.jp