fs
Filesystem access. File implements both Read and Write, so code already written against the I/O traits works against files with no glue.
public module fs::path;
public module fs::file;
public module fs::metadata;
public module fs::dir;
| File | What it holds | Import |
|---|---|---|
path | Path (borrowed) and PathBuf (owned) | import std::fs::path; |
file | File, OpenOptions, and the whole-file helpers read, write, copy | import std::fs::file; |
dir | read_dir, create_dir, remove_file, rename, canonicalize | import std::fs::dir; |
metadata | Metadata, FileType, metadata, exists | import std::fs::metadata; |
public function name() { ... }
public:Visible to any module that imports this one - the default for top-level items and for struct fields, so it is mostly written to be explicit. public: opens a visibility block that groups the members after it.
public module collections::array;In a directory's _module.cryo aggregator, lists a submodule and whether it is public. Importing the directory's namespace sees only the modules declared public here.
namespace std::fs::metadata;File metadata: a typed Metadata snapshot of a path's type, size, and modification time.
type struct Path {
inner: Str;
}Path / PathBuf: filesystem paths as length-typed UTF-8.
std::fs::pathtype struct PathBuf<A = GlobalAlloc> {
inner: String<A>;
}import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
type struct OpenOptions {
read: boolean;
write: boolean;
append: boolean;
truncate: boolean;
create: boolean;
create_new: boolean;
}type struct Metadata {
raw_mode: u32;
byte_size: u64;
mtime_sec: i64;
}A snapshot of a path's metadata. POD (no owned resources), freely copied; no drop needed.
type enum FileType {
File;
Dir;
Symlink;
Other;
}The broad category of a filesystem entry.
std::fs::metadata