Skip to main content

Crate alpha2_os

Crate alpha2_os 

Source
Expand description

The operating-system calls the native host makes that the standard library does not offer at this workspace’s minimum Rust version, behind safe functions: an advisory lock on a file, a rename that never replaces its target, a handler for a request to terminate the process, the process’s resident memory, the work the calling thread has done, and a diagnostic line on standard error that a closed stream does not turn into a panic.

The rest of the workspace forbids unsafe; this crate, like alpha2-ffmpeg-bridge, is where the few calls that need it are kept and reviewed.

Macros§

diagnostic
eprintln! for the native host and its libraries: the same line on standard error, dropped when the stream cannot take it (write_diagnostic).

Structs§

ProcessMemory
The process’s resident memory, as the operating system counts it.
Termination
A request to end the process: an interrupt or termination signal on Unix, a console control event on Windows.

Functions§

on_termination
Calls handler on a thread of its own each time the process is asked to terminate, instead of the process ending at once.
process_memory
The process’s resident memory now and at its peak; a figure the operating system does not report (or this build does not read on it) is None.
rename_no_replace
Renames from to to unless to exists, in one step: a file that appears at to at any moment, up to the rename itself, is never replaced, and the rename fails with io::ErrorKind::AlreadyExists.
same_file
Whether path names the file file is open on now: false when the path no longer exists, names another file (one removed and created again), or names a removed file that some handle keeps open (file’s own included): Windows and an SMB share keep such a name until the last handle closes.
same_file_at
Whether the paths a and b name one file: the same device and inode on Unix, the same volume serial and file index on Windows. Hard links and paths through symbolic links to one file are the same file; two copies are not. false when either path names nothing.
thread_cpu_work
The work the calling thread has done so far, as a count that only this thread’s other readings are comparable to: CPU nanoseconds on Unix (CLOCK_THREAD_CPUTIME_ID), CPU cycles on Windows (QueryThreadCycleTime). Time the thread spent waiting for a CPU, as on a busy machine, is not in it, which is what a test that compares the work of two input sizes needs. None where the operating system does not report it (or this build does not read it there).
try_lock_exclusive
Takes an exclusive advisory lock on file without waiting: Ok(true) when this handle now holds it, Ok(false) when another open handle (in this process or another) does.
write_diagnostic
Writes one line to standard error, the way eprintln! does, and drops it when the stream is closed or full instead of panicking.