FileSystem v0.1.0
Files, directories and filesystem operations
Installation
Add FileSystem to the [Dependencies] table of your package's Rux.toml:
[Dependencies]
FileSystem = { Namespace = "Rux", Version = "0.1.0" }
Standard packages are declared by hand: the registry does not serve them, so rux add Rux/FileSystem cannot add them.
Dependencies
Allocator0.1.0Core0.1.0Entropy0.1.0FreeBSD0.1.0 (FreeBSD only)Io0.1.0Linux0.1.0 (Linux only)macOS0.1.0 (macOS only)Path0.1.0Text0.1.0Time0.1.0Windows0.1.0 (Windows only)
Guide
What it provides
FileandOpenOptions— a move-only owned handle the type system closes exactly once and copyable options created withOpenOptions(). Safe operations borrow the handle through&Fileor&var File; only stored platform handles and explicit output slots remain raw pointers.- Deterministic owners — directory iterators, temporary files and directories, and atomic writes prohibit copying, transfer with
<-, and clean up through~Typedestructors. Fallible operations such asOpen,Create, andBeginkeep their descriptive names. - A file is a stream, and a stream is usually a borrow —
FileimplementsReader,WriterandSeeker, so anything wanting a stream for the length of a call takes the file:WriteAll(file, contents)?;
The borrow is checked and ends at the call, which means the compiler also refuses reading the file through while a borrow of it is still live.FileStreamis the stored form, for a value such as aBufferedReaderthat keeps its source past the call that made it — binding the file itself into an interface value there would move it, and there would be nothing left to close. Its representation is private andFile::Streamis the only way to obtain one; it must not outlive the file or survive a move of it, and nothing tracks either. A stream over a closed file is not unsafe: the file checks its own handle, so every operation refuses withInvalidHandle.AtomicWriteis itself aWriter, so replacing a file needs no adapter at all. - Native error translation — every operation that can fail returns a native fallible whose failure is an
Io::IoError: the kind a caller acts on, with the platform's raw code preserved beside it, translated by one table per platform rather than ad hoc at each call site.File::Open,ReadDirectory,MetadataOf, and the other constructors and queries succeed with their value, and the rest succeed with(); a directory iterator'sNextsucceeds withnoneat the end.
Index
Types
| Name | Summary |
|---|---|
AtomicWrite | A file being written to replace target, which appears under that name only when it is complete. |
DirectoryIterator | A directory read one entry at a time. |
OpenOptions | What an open may do, and what it does about existence. |
File | An owned, open file. |
FileStream | A stored borrow of an open file that speaks the stream interfaces. |
FileKind | What kind of thing a name refers to. |
Permissions | Who may do what to a file, in both spellings the supported systems use. |
Metadata | Everything a single query can say about a file. |
Capabilities | What the running system can actually answer, so a caller can ask before it assumes. |
TemporaryFile | A temporary file that owns both its contents and its name. |
TemporaryDirectoryHandle | A temporary directory that owns its name. |
Functions
| Name | Summary |
|---|---|
WriteAtomically | Replaces target with contents, atomically. |
MakeDirectory | Creates the directory path names. |
DeleteDirectory | Deletes the empty directory path names; a directory with anything still in it is refused. |
DeleteFile | Deletes the file path names. |
ReadDirectory | Begins enumerating the directory path names. |
CurrentDirectory | The process's working directory, as an absolute path. |
SetCurrentDirectory | Makes path the process's working directory. |
Absolute | path made absolute against the working directory and simplified lexically. |
Canonicalize | The one true name of the existing file path refers to. |
CapabilitiesOfSystem | What this system can answer. |
MetadataOf | Describes the file path names. |
SetPermissions | Sets who may do what to the file path names. |
SetTimes | Sets the access and modification times of the file path names. |
TemporaryDirectory | The directory the system sets aside for temporary files. |
Rename | Renames from to to, moving it between directories if the paths differ there. |
CreateHardLink | Creates link as a hard link: a second name for the file existing names. |
CreateSymbolicLink | Creates link as a symbolic link holding target as its text. |
CopyFile | Copies the file from names to to, following a symbolic link to the bytes it points at. |
NativeKind | The meaning of a platform error code on the platform this program was compiled for. |
TranslateNative | A platform error code as the structured error everything here reports. |
Constants
| Name | Summary |
|---|---|
SymbolicLinkLimit | How many symbolic links one canonicalization will follow before giving up. |
TemporaryNameAttempts | How many names are tried before a temporary file gives up. |