Expand description
Safe wrappers for the operating-system calls the native host needs that the standard library does not offer at the minimum Rust version: file locks, no-replace publishing, termination handling, parent and child lifetime, clocks, memory, and the OS version.
The rest of the workspace forbids unsafe; this crate and alpha2-ffmpeg-bridge hold the few
calls that need it.
Macros§
- diagnostic
eprintln!that drops the line instead of panicking (write_diagnostic).
Structs§
- Awake
Instant - A point on a clock that stops while the system sleeps, so stall checks ignore suspend.
- Kill
OnClose Job - A Windows job that kills its processes when dropped or when this process ends, for probe children that may hang. A no-op elsewhere.
- Memory
Capacity - The machine’s memory and this process’s limit. Unavailable figures are
None. - Name
Limit - The longest file name a directory takes.
- Process
Memory - The process’s memory, as the operating system counts it.
- Published
- A finished file moved into place.
- Retry
Policy - How long a publish retries a step refused by another program’s open handle.
- Termination
- A request to end the process: an interrupt or termination signal on Unix, a console control event on Windows.
Enums§
- Name
Unit - What a
NameLimitcounts. - Publish
Method - How
publish_no_replaceorpublish_replacemoved a file into place.
Functions§
- cgroup_
v2_ usage - The process’s cgroup v2
(working set, memory.max)when it has a limit. The working set excludes reclaimableinactive_filepage cache, which the kernel drops at the limit instead of killing anything. - exit_
without_ handlers - Ends the process now with
code, without running exit handlers. The caller must flush first. - file_
version - The
major.minor.build.revisionfrom the Windows version resource ofpath;Noneelsewhere or without one. - is_
retryable_ publish_ error - Whether a publish step failed because another program (antivirus, indexer, media player)
briefly holds the file open:
ERROR_ACCESS_DENIED,ERROR_SHARING_VIOLATIONorERROR_LOCK_VIOLATIONon Windows. Alwaysfalseon Unix, where open handles do not block a rename. - memory_
capacity - The machine’s memory and this process’s limit, read now.
- memory_
capacity_ at memory_capacitywithrootstanding in for/.- name_
limit - The longest file name
diraccepts:pathconf(_PC_NAME_MAX)on Unix (255 bytes if unreported), 255 UTF-16 units on Windows. - on_
termination - Calls
handleron its own thread when the process is asked to terminate, instead of ending at once.watch_parentcalls the same handler. - os_
version - The OS version, read once:
27.0.1 (26A434)on macOS,Ubuntu 22.04.5 LTS, kernel 6.8.0on Linux,10.0.26300.9711on Windows. Missing parts are omitted;unknownif all are. - prefer_
fast_ cores - Asks the scheduler to keep the calling thread on the fastest cores, so
thread_cpu_workreadings come from one kind of core:QOS_CLASS_USER_INTERACTIVEon macOS, noEcoQoSthrottling on Windows, nothing elsewhere. Best effort; failures are silent. - process_
cpu_ time - User plus system CPU time of all the process’s threads so far;
Nonewhere unavailable. - process_
memory - The process’s memory now and at its peak; unavailable figures are
None. - publish_
no_ replace - Moves the finished file
fromtoto, never replacing an existing file atto. - publish_
replace - Moves the finished file
fromtoto, replacing any file there. Retryable errors are retried asretryallows. - quarantined
- Whether
pathhas the macOScom.apple.quarantineattribute, under which Gatekeeper refuses to load an unnotarized library.falseon other systems and for unreadable files. - same_
file - Whether
pathstill names the filefileis open on.falsewhen the path is gone, names a recreated file, or names a removed file kept visible by an open handle (Windows and SMB keep such names until the last handle closes). - same_
file_ at - Whether
aandbname one file (same device and inode, or volume serial and file index on Windows). Hard links and symlinks count as the same file.falsewhen either path is missing. - stop_
std_ handle_ inheritance - Stops children from implicitly inheriting this process’s standard handles (Windows only).
- sync_
directory - Makes renames into
dirsurvive a power loss byfsyncing it on Unix. File systems that cannot sync a directory are not an error. No-op on Windows, where the rename writes through. - thread_
cpu_ work - The calling thread’s CPU work so far, comparable only with other readings on the same thread:
CPU nanoseconds on Unix, cycles on Windows (
QueryThreadCycleTime). Excludes time spent waiting for a CPU.Nonewhere unavailable. - try_
lock_ exclusive - Takes an exclusive advisory lock on
filewithout waiting. ReturnsOk(false)when another open handle, in this or another process, holds it. - utf8_
arguments - The arguments as UTF-8 strings. Unlike
std::env::args, a non-UTF-8 argument is an error, not a panic. - watch_
parent - Calls the
crate::on_terminationhandler with aPARENT_EXITEDtermination (status 143) when the parent process exits, or at once if it already has. - with_
publish_ retries - Runs
stepuntil it succeeds, fails with a non-retryable error, orretrystops it. Waits 50 ms before the first retry, doubling up to 1 s. Returns the value and the retry count. - write_
diagnostic - Writes one line to standard error like
eprintln!, but drops it instead of panicking when the stream is closed, so a client closing the pipe cannot abort an export. Usediagnostic!.