Module

std::fs::metadata

File Metadata

Platform-independent file metadata and file type classification.

Fs::Metadata wraps the raw POSIX Stat record and exposes a portable API. Fs::FileType is an enum that classifies entries as regular files, directories, or symlinks without requiring callers to know about S_IFMT masks or DT_* constants.

Types

Type Description
Metadata File size, timestamps, permissions, and file type
FileType Classification: FILE, DIRECTORY, SYMLINK, OTHER

Construction

Users do not create Metadata directly. Instead, obtain it from:

  • Fs::metadata(path) (stat by path)
  • file.metadata() (fstat on open file)

Example

import Fs from "std::fs";
import Io from "std::io";

function main(): i32 {
  let result: Result<Fs::Metadata, Io::IoError> = Fs::metadata("/etc/hosts");
  if (result.isError()) {
    return 1;
  }

  let meta: Fs::Metadata = result.unwrap();
  if (meta.isFile()) {
    let size: i64 = meta.len();
    return 0;
  }

  return 1;
}
namespace Fs

Records

record Metadata

Platform-independent file metadata.

Wraps the raw POSIX Stat and provides portable accessors. Obtained via Fs::metadata(path) or file.metadata().

Members
size: i64

File size in bytes.

mode: u32

POSIX mode bits (permissions + file type mask).

atime: i64

Last access time (seconds since Unix epoch).

mtime: i64

Last modification time (seconds since Unix epoch).

ctime: i64

Last status change time (seconds since Unix epoch).

fileType(&self): FileType

Returns the classified file type.

accessedTime(&self): i64

Returns the last access time in seconds since Unix epoch.

createdTime(&self): i64

Returns the last status change time in seconds since Unix epoch.

fileType(&self): FileType

Returns the classified file type.

isDir(&self): boolean

Returns true if this is a directory.

isFile(&self): boolean

Returns true if this is a regular file.

isSymlink(&self): boolean

Returns true if this is a symbolic link.

len(&self): i64

Returns the file size in bytes.

modifiedTime(&self): i64

Returns the last modification time in seconds since Unix epoch.

permissions(&self): u32

Returns the raw POSIX permission bits (lower 12 bits of mode).

Enums

enum FileType

Classification of a filesystem entry.

Members
FILE
DIRECTORY
SYMLINK
OTHER

Functions

function fileTypeFromDirent(dtype: u8): FileType

Classifies a dirent d_type value into a FileType.

function fileTypeFromMode(mode: u32): FileType

Classifies a POSIX mode value into a FileType.

Uses the S_IFMT mask to extract the file type bits.

function metadataFromStat(st: &Stat): Metadata

Converts a raw Stat into a high-level Metadata.