gd_host¶
gd-host: where the Guidedoc engine meets the operating system. Sessions that convert with Ctrl+C cancellation; sources read within limits (UTF-8 checked, byte order mark dropped); included files confined to approved roots; atomic publication; engine diagnostics as gd_report::Reports; a coarse memory budget; worker threads with known stacks; a crash reporter; and convert_artifact, the route guidedog convert takes from a file to a published HTML or PDF artifact.
use gd_host::{Session, describe_all};
let registry = guidedoc::Registry::default(); // guidedoc_defaults::registry() in a program
let mut session = Session::new();
let request = guidedoc::default_request("hello.rst", "Hello *world*.\n", "rst", "html");
let result = session.run(®istry, &request).map(str::to_owned);
for report in session.reports() {
eprint!("{}", gd_report::render_text(&report, &gd_report::Style::default()));
}
if let Ok(html) = result {
println!("{html}");
}
Failures are Problems (code, title, message, hint, exit status) or engine Fails described as reports; nothing here prints except catch_crash, the last resort.
Structs
- pub struct gd_host::ArtifactRequest<'a>¶
-
One conversion of
guidedog convert. Everything is borrowed for the call; fill it with struct-update syntax fromDefault.Fields
- pub input: &'a str¶
-
The input path, or
"-"for standard input.
- pub output: &'a str¶
-
The output path, or
"-"for standard output.
- pub force: bool¶
-
Replace existing outputs.
- pub read: ReadOptions<'a>¶
-
Read options.
- pub render: RenderOptions<'a>¶
-
Render options.
- pub typst_program: &'a str¶
-
The Typst program name or path;
""or"typst"uses the embedded compiler.
- pub typst_options: gd_typst::Options<'a>¶
-
Typst packages and fonts;
reserveis set by the route (it charges the budget).
- pub passes: &'a [Pass<'a>]¶
-
Transforms run between reading and rendering (embedded pictures, typeset math).
- pub roots: &'a [PathBuf]¶
-
Approved roots for included files; the input’s folder when empty.
- pub budget: usize¶
-
Memory budget in bytes for what the route holds; 0 is
DEFAULT_BUDGET.
Trait Implementations
- impl fmt::Debug for ArtifactRequest<'_>
-
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
- pub struct gd_host::ArtifactResult¶
-
What
convert_artifactdid. Reports are kept whatever the outcome;exitis 0 on success, else the status the command ends with, explained byproblemor by the error reports.Fields
- pub exit: i32¶
-
The process exit status.
- pub struct gd_host::Budget¶
-
Bounds the bytes a build holds at once, shared by its threads (
BudgetisSync).Units of work that run at once (
join) wait for each other: a reservation the budget cannot hold now waits while another joined unit runs, since that one releases what it holds when it ends. When every other unit waits too, nothing would be released, and the reservation is refused instead, so the budget never deadlocks. A reservation larger than the whole limit goes to the policy at once.Implementations
- impl Budget
-
- pub fn with_policy(limit: usize, on_refusal: impl Fn(&Refusal) -> RefusalChoice + Send + Sync + 'static) -> Budget¶
-
Makes a budget of
limitbytes that askson_refusalwhat to do with a reservation it cannot hold (a terminal build asks the user whether to raise it).
- pub fn limit(&self) -> usize¶
-
The limit now; a policy may have raised it.
- pub fn set_limit(&self, limit: usize)¶
-
Sets the limit; reservations waiting are woken to try again.
- pub fn used(&self) -> usize¶
-
The bytes held now.
- pub fn peak(&self) -> usize¶
-
The most bytes held at once.
Trait Implementations
- impl std::fmt::Debug for Budget
-
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
- pub struct gd_host::Ledger<'b>¶
-
Counts what one unit of work (a document’s read, a page, a conversion) holds of a budget: the files it reads, the outputs it keeps. Each charge is made before the memory is allocated; dropping the ledger (or
settle) releases them all. A ledger without a budget accepts every charge. Its methods take&self, so a resource provider can charge through a shared reference, from several threads.Implementations
- impl<'b> Ledger<'b>
-
- pub fn charge(&self, bytes: usize) -> bool¶
-
Reserves
bytes, waiting asBudgetdescribes. Returns false, reserving nothing, when the budget refuses;refusedthen tells the bytes asked for.
- pub fn discharge(&self, bytes: usize)¶
-
Returns
bytesthe unit has freed before it ends (at most what it holds).
- pub fn settle(&self)¶
-
Releases everything the ledger holds.
- pub fn held(&self) -> usize¶
-
The bytes held now.
- pub fn refused(&self) -> usize¶
-
The bytes the last refused charge asked for, or 0.
Trait Implementations
- impl Drop for Ledger<'_>
-
- fn drop(&mut self)
- pub struct gd_host::Refusal¶
-
What a budget tells its policy when it cannot hold a reservation.
Fields
- pub need: usize¶
-
The bytes asked for.
- pub used: usize¶
-
What the budget holds.
- pub limit: usize¶
-
Its limit.
- pub struct gd_host::Unit<'b>¶
-
A unit of work counted by
Budget::join; dropping it ends the unit.Trait Implementations
- impl Drop for Unit<'_>
-
- fn drop(&mut self)
- pub struct gd_host::Files<'l>¶
-
Provides included files from approved roots. It refuses Docutils‘
<standard>includes, names that leave the roots, and names that pass through a symbolic link: links are checked on the path as written, component by component, before it is resolved; then the resolved path must still lie in a root.let ledger = gd_host::Ledger::unbounded(); let files = gd_host::Files::new(&["docs"]).with_ledger(&ledger); let request = guidedoc::Request { resources: Some(&files), ..Default::default() };
Fields
- pub max_bytes: usize¶
-
The largest file served, in bytes.
- pub project: Option<PathBuf>¶
-
When set, a name starting with
/is relative to this folder, as Sphinx reads/pathinincludeandliteralinclude; otherwise such a name is absolute.
- pub ledger: Option<&'l Ledger<'l>>¶
-
When set, each file’s size is charged here before it is read; a file the budget cannot hold is
ResourceStatus::Limit. The charges last as long as the ledger.
Implementations
- impl Files<'static>
- impl<'l> Files<'l>
-
- pub fn with_ledger<'m>(self, ledger: &'m Ledger<'m>) -> Files<'m> where 'l: 'm¶
-
The same provider, charging each file to
ledger, which it borrows.
- pub fn with_project(self, project: impl Into<PathBuf>) -> Files<'l>¶
-
The same provider, reading names that start with
/belowproject.
- pub fn roots(&self) -> &[PathBuf]¶
-
The resolved roots.
- pub fn missing(&self) -> Vec<PathBuf>¶
-
The files asked for so far that did not exist, absolute and sorted, each once. A reader records them as dependencies, so a document that includes a file that is created later is read again.
Trait Implementations
- impl ResourceProvider for Files<'_>
-
- fn provide(&self, from: &str, name: &str) -> Result<Resource, ResourceStatus>
- pub struct gd_host::SourceFile¶
-
An input read by
read_source: its text and the name the conversion knows it by.Fields
- pub struct gd_host::FolderEntry¶
-
A name in a folder, what it names, and its inode as the listing gives it (0 where the system gives none).
Fields
- pub name: OsString¶
-
The entry’s name.
- pub inode: u64¶
-
The inode, or 0.
- pub struct gd_host::Identity¶
-
A file’s or a folder’s device and inode, which a rename keeps: two paths with the same identity name the same file.
Fields
- pub device: u64¶
-
The device.
- pub inode: u64¶
-
The inode.
- pub struct gd_host::Problem¶
-
A host failure: a file that cannot be read, an output that exists, a budget reached, a Typst program that is missing. It carries the exit status the command ends with. Turn it into a report with
Problem::reportto render it.Fields
- pub code: &'static str¶
-
A stable code such as
"host.io".
- pub title: &'static str¶
-
A short upper-case title such as
"CANNOT ACCESS THIS PATH".
- pub exit: i32¶
-
The process exit status: 2 usage or file type, 3 limits and memory, 4 I/O and Typst, 130 cancelled.
Implementations
- impl Problem
Trait Implementations
- impl fmt::Display for Problem
-
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
- impl std::error::Error for Problem
- pub struct gd_host::Stage¶
-
A staging file beside a destination, for output written in place by another producer (Typst) or by
publish. Dropping it removes the file unless it was committed, so an abandoned stage leaves nothing behind.Implementations
- impl Stage
-
- pub fn beside(destination: &Path) -> Result<Stage, Problem>¶
-
Creates an empty staging file in the folder of
destination, making the folders on its way. Fails withhost.io.
- pub fn commit(mut self, destination: &Path, force: bool) -> Result<(), Problem>¶
-
Flushes the staging file and renames it over
destination, then flushes the folder so the name is durable. An existing destination is refused (host.output.exists) unlessforceis set; on any failure the destination is unchanged and the stage removed.
Trait Implementations
- impl Drop for Stage
-
- fn drop(&mut self)
- pub struct gd_host::Schedule¶
-
The jobs of a parallel run, numbered in the order a sequential run takes them, and the memory they may reserve together. Plain data; one schedule per run.
Implementations
- impl Schedule
-
- pub fn new(weights: Vec<u64>, capacity: u64, slots: usize) -> Schedule¶
-
A schedule of
weights.len()waiting jobs, which may reservecapacitybytes together and run at mostslotsat once (0 counts as 1).
- pub fn job_count(&self) -> usize¶
-
The number of jobs.
- pub fn phase(&self, job: usize) -> JobPhase¶
-
Where
jobis. Panics whenjobis not a job of the schedule.
- pub fn load(&self) -> u64¶
-
The memory the running jobs reserve.
- pub fn running_count(&self) -> usize¶
-
How many jobs run.
- pub fn may_start(&self, job: usize, room: impl Fn(u64) -> bool) -> bool¶
-
Whether
jobmay start now: the guard ofstart.roomis asked about the job’s weight only when other jobs run.
- pub fn next(&self, room: impl Fn(u64) -> bool) -> Option<usize>¶
-
The job to start next, if one may start: the heaviest, and of equal weights the earliest, so that light jobs fill the gaps at the end.
- pub fn start(&mut self, job: usize)¶
-
Marks
jobas running. Panics when it may not start, whateverroomsays: the caller asksSchedule::nextorSchedule::may_startfirst.
- pub fn finish(&mut self, job: usize, succeeded: bool)¶
-
Marks the running
jobas ended. Panics when it does not run.
- pub fn is_ended(&self) -> bool¶
-
Whether no job runs and none may start: the run has ended. A sequential run would have ended in the same outcome (GDS 0020, Theorems 4 and 5).
- pub struct gd_host::Session¶
-
One thread’s conversions. Reuse it: its workspace keeps its buffers between runs. What a run returns (output, document) and
reportsdescribe the last run only.Implementations
- impl Session
-
- pub fn run(&mut self, registry: &Registry, request: &Request<'_>) -> Result<&str, Fail>¶
-
Converts
requestwithregistry: read, passes, render. A request without a cancel probe gets the Ctrl+C one (cancel_probe). The output borrows the session until the next run; on failure,reportsexplains it.
- pub fn read(&mut self, reader: &Reader, request: &Request<'_>) -> Result<Document<'_>, Fail>¶
-
Reads
request’s source withreaderwithout rendering, then runsrequest.passesover the document (a translation, for example). The document borrows the session until the next run.
- pub fn document(&self) -> Option<Document<'_>>¶
-
The current document: the last successful read or run.
- pub fn reports(&self) -> Vec<Report>¶
-
Describes what the last run reported (
describe_all); the reports are owned.
Enums
- pub enum gd_host::Delivered¶
-
Where a successful conversion’s artifact went.
Variants
- Nothing¶
-
Nothing was delivered (the conversion failed).
- File(PathBuf)¶
-
Published at this path.
- Stdout(Vec<u8>)¶
-
The bytes to print, for output
"-".
- pub enum gd_host::Format¶
-
The markup
convert_artifactreads.Variants
- Rst¶
-
reStructuredText (reader
rst).
- Commonmark¶
-
CommonMark (reader
commonmark).
- Myst¶
-
MyST Markdown (reader
myst; the read options carry the Sphinx layer).
- Sphinx¶
-
reStructuredText with the Sphinx layer (reader
sphinx).
- Typst¶
-
Native Typst, compiled as it is.
Implementations
- pub enum gd_host::Target¶
-
The artifact
convert_artifactpublishes.Variants
- Html¶
-
An HTML page (renderer
html; Typst’s HTML export for Typst input).
- Pdf¶
-
A PDF document (renderer
typst, then the Typst compiler).
- Rst¶
-
reStructuredText source (renderer
rst), written as text like HTML.
Implementations
- pub enum gd_host::RefusalChoice¶
-
What a budget’s policy decides about a reservation it cannot hold.
Variants
- Stop¶
-
Refuse it, and every later one without asking again.
- Raise(usize)¶
-
Raise the limit to this many bytes (more than
Refusal::limit) and try again.
- pub enum gd_host::Confinement¶
-
Where a path lies with respect to the roots a project reads from.
Variants
- Inside¶
-
Confined: below a root once every link is followed.
- Outside¶
-
The path as written is below no root.
- ThroughLink¶
-
Written below a readable folder, but a link on the way leads out of the roots.
- pub enum gd_host::PathKind¶
-
What a path names, never following a symbolic link.
Variants
- File¶
-
A regular file.
- Folder¶
-
A folder.
- Link¶
-
A symbolic link, whatever it leads to.
- Other¶
-
Anything else (a device, a socket, a pipe).
- pub enum gd_host::JobPhase¶
-
Where a job is.
Variants
- Waiting¶
-
Not started.
- Running¶
-
Started and not ended.
- Succeeded¶
-
Ended with success.
- Failed¶
-
Ended with failure.
Functions
- pub fn gd_host::backend_problem(program: &str) -> Problem¶
-
The problem of a Typst program that cannot be found (
typst.missing, exit 4).
- pub fn gd_host::convert_artifact(registry: &Registry, req: &ArtifactRequest<'_>) -> ArtifactResult¶
-
Converts one file to a published HTML, PDF, or reStructuredText artifact: reads the input within
MAX_SOURCE_BYTES, converts it withregistry(the readers and renderersFormat::readerandTarget::renderername) and includes confined to the roots, runs Typst for PDF, and publishes atomically, or returns the bytes for"-". The budget bounds what the route holds: the source, its includes, and the PDF the embedded compiler returns. A failure leaves any existing output unchanged.
- pub fn gd_host::available_memory() -> Option<usize>¶
-
The memory this machine has free, in bytes: the value of
AVAILABLE_OVERRIDEin MiB when set, else what the system reports (GDS 0020). On Linux that isMemAvailablefrom/proc/meminfo, lowered to what the process’s control group may still use (cgroup_room); on macOS, the free, speculative and inactive pages thatvm_statcounts; on Windows,ullAvailPhysofGlobalMemoryStatusEx.Nonewhen the system does not say.
- pub fn gd_host::budget_advice(used: usize, need: usize, limit: usize, available: Option<usize>, other: &str) -> String¶
-
The text of
budget_hint, for a step that asked forneedbytes while the budget heldusedoflimit, on a machine withavailablebytes free (None: unknown).
- pub fn gd_host::budget_hint(budget: Option<&Budget>, need: usize, other: &str) -> String¶
-
The hint of a budget’s problem: the budget the refused step fits in, from what
budgetheld and was asked for when it last refused (needwhen it refused nothing itself), capped by the machine’s free memory, and the other way out the caller names (other, lower case, without a full stop).
- pub fn gd_host::budget_problem(what: &str, path: &str, bytes: usize, budget: Option<&Budget>) -> Problem¶
-
Explains a charge
budgetrefused (host.budget, exit 3): what neededbytes, and where. The hint names a budget that fits (budget_hint).
- pub fn gd_host::fitting_budget(available: usize) -> usize¶
-
A budget that fits in
availablefree bytes: nine tenths of it, in steps of 16 MiB; 0 when there is no room for even one step (never offer 0 to the CLI, where it means the default).
- pub fn gd_host::limits_within(limits: Limits, budget: usize) -> Limits¶
-
limitswith the byte bounds of one conversion (text pool, output, included sources) lowered tobudgetbytes, so no single conversion is allowed more than the whole budget. Abudgetof 0 leaves the limits as they are.
- pub fn gd_host::peak_memory() -> Option<u64>¶
-
The peak resident memory of this process so far, in bytes:
VmHWMfrom/proc/self/statuson Linux,ru_maxrssofgetrusageon macOS, and the peak working set on Windows;Noneelsewhere or when the system does not say.
- pub fn gd_host::suggest_budget(used: usize, need: usize, limit: usize, available: Option<usize>) -> (usize, bool)¶
-
The budget in bytes to suggest so that one change is enough: what is held plus the request four times over (a step also holds its output and the copy it writes), or twice the old limit, whichever is larger, in steps of 64 MiB. With
availableknown and smaller, the budget is capped tofitting_budget, or is what is needed in steps of 16 MiB when even that does not fit;fitsis then false.
- pub fn gd_host::canonical_roots<P: AsRef<Path>>(roots: &[P]) -> Vec<PathBuf>¶
-
Resolves
rootsto absolute paths with every link followed, asconfinedcompares paths with them; a root that cannot be resolved is made absolute as written (it then matches nothing that exists through a link, so it never widens what is allowed).
- pub fn gd_host::confined(roots: &[PathBuf], path: &Path) -> bool¶
-
Reports whether
path(a document, an image, a template a project reads) lies in one of the canonicalroots: written below a root with no link on the way, or below a root once every link is resolved.
- pub fn gd_host::confinement(roots: &[PathBuf], path: &Path) -> Confinement¶
-
Tells whether
confinedacceptspath, and when it does not, whether the path itself or a link on its way leads outside, so a refusal can say which.
- pub fn gd_host::containing_root<'r>(roots: &'r [PathBuf], path: &Path) -> Option<&'r Path>¶
-
The root of
rootsthatpathis written below (or is), comparing whole components and following no link;confinedis the check that follows them.
- pub fn gd_host::catch_crash(command: impl FnOnce() -> i32) -> i32¶
-
Runs
commandand returns its exit status; a panic that unwinds out of it prints the crash report to standard error and returnsCRASH_EXIT.
- pub fn gd_host::crash_report(cause: &str) -> String¶
-
The whole report for
cause, from the partsinstall_crash_reporterprepared.
- pub fn gd_host::install_crash_reporter(args: &[String], version: &str)¶
-
Prepares the crash report for the command line
args(the program name first) andversion(whatguidedog --versionprints), and installs a panic hook that records each panic’s message and location without printing it.
- pub fn gd_host::describe(ws: &Workspace, d: &Diagnostic) -> Report¶
-
Turns a diagnostic of the conversion
wsholds into a report: its message and hint with{0}/{1}filled (span arguments quoted from the sources, cut at 60 characters), the source’s path asdisplay_pathshows it, and the line, columns, and excerpt of its span. The report copies what it needs and outlivesws.
- pub fn gd_host::describe_all(ws: &Workspace) -> Vec<Report>¶
-
Describes every diagnostic the last conversion in
wsreported, in order; the primary error too when the store was full before it, and a note counting the diagnostics the store had no room for.
- pub fn gd_host::display_path(name: &str) -> String¶
-
namerelative to the working directory when that reads shorter (not three or more folders above it), andnameitself otherwise, for „“ and „-„, and for names that are not absolute paths.
- pub fn gd_host::exit_code(status: Status) -> i32¶
-
Maps a conversion status to the exit status Guidedog’s commands use: 0 ok, 1 invalid input, unsupported or policy, 3 capacity or limits, 5 internal, 130 cancelled.
- pub fn gd_host::each_chunk(path: &Path, mut each: impl FnMut(&[u8]) -> bool) -> bool¶
-
Reads a file through a stack buffer, giving each chunk to
eachuntil it returns false. Returns whether the whole file was read and accepted.
- pub fn gd_host::read_file(path: &Path, ledger: Option<&Ledger<'_>>, limit: usize) -> Result<Vec<u8>, Problem>¶
-
Reads a regular file of at most
limitbytes whole, charging its size toledgerbefore allocating; the ledger keeps the charge until the caller discharges or drops it. A file that grows while it is read is refused; one that shrinks keeps its full charge (fewer bytes read do not mean fewer bytes held).
- pub fn gd_host::read_source(path: &str, limit: usize) -> Result<SourceFile, Problem>¶
-
Reads a named input, or standard input for
"-", of at mostlimitbytes, checks that it is UTF-8 and drops a leading byte order mark. Fails withhost.io,host.file-type,host.limit.source, orhost.utf8(with the line and column of the first bad byte).
- pub fn gd_host::read_stream(stream: &mut impl Read, name: &str, limit: usize) -> Result<Vec<u8>, Problem>¶
-
Reads a stream of unknown length (a pipe, standard input) within
limitbytes, probing one byte past the limit: neither an endless pipe nor a growing file can force an unbounded allocation.namenames the stream in problems.
- pub fn gd_host::same_contents(path: &Path, data: &[u8]) -> bool¶
-
Reports whether the file at
pathholds exactlydata, reading it in chunks and stopping at the first difference; false when it cannot be read.
- pub fn gd_host::exchange(a: &Path, b: &Path) -> io::Result<bool>¶
-
Swaps the names of two existing paths in one step where the system can (Linux’s
renameat2withRENAME_EXCHANGE, macOS’srenamex_npwithRENAME_SWAP), so a reader sees one folder or the other, never neither.Ok(false), changing nothing, where the system or the file system cannot: the caller then renames in two steps.
- pub fn gd_host::identity(path: &Path) -> io::Result<Option<Identity>>¶
-
The identity of what is at
path(not following a link);Nonewhen nothing is, or where the system gives no inode (Windows).
- pub fn gd_host::link_file(from: &Path, to: &Path, kind: PathKind) -> io::Result<bool>¶
-
Makes
toname the same file asfrom: a hard link, or a copy where the file system cannot link (FAT, some network shares), whichOk(true)reports and the caller must flush. A symbolic link (kindisPathKind::Link) is made again, to the same target. An existingtois an error, never replaced.
- pub fn gd_host::list_folder(dir: &Path) -> io::Result<Vec<FolderEntry>>¶
-
Lists a folder’s entries in the order the system gives them, each with its kind from the listing itself (no entry is opened, which matters for thousands of files).
- pub fn gd_host::path_type(path: &Path) -> io::Result<Option<PathKind>>¶
-
What is at
path, not following a symbolic link;Nonewhen nothing is.
- pub fn gd_host::remove_path(path: &Path) -> io::Result<()>¶
-
Removes a file, a link, or an empty folder.
- pub fn gd_host::remove_tree(path: &Path) -> io::Result<()>¶
-
Removes what is at
path, a whole folder tree included, without following a symbolic link: a link is removed, never what it leads to. A work list replaces recursion, so deep folders cannot exhaust the stack. Nothing atpathis nothing to remove; the first entry that cannot be removed ends it with its error.
- pub fn gd_host::cancel_probe() -> &'static (dyn Fn() -> bool + Sync)¶
-
The probe a
guidedoc::Requestpolls (request.cancel) to stop at Ctrl+C; it holds no state of its own.
- pub fn gd_host::catch_interrupts() -> bool¶
-
Makes Ctrl+C (SIGINT) set the interrupt flag instead of ending the process, for the whole process. A program calls it once, at the start; false when the system refused.
- pub fn gd_host::clear_interrupt()¶
-
Clears the interrupt flag, for a long-running embedder that goes on after a cancel.
- pub fn gd_host::request_interrupt()¶
-
Sets the interrupt flag as Ctrl+C does, for an embedder that cancels by other means (a server’s stop button, a test).
- pub fn gd_host::was_interrupted() -> bool¶
-
Reports whether Ctrl+C was pressed (or
request_interruptcalled) since the start.
- pub fn gd_host::interrupted_problem() -> Problem¶
-
The problem, with exit status 130, of a command stopped by Ctrl+C.
- pub fn gd_host::io_problem(path: &Path, error: &std::io::Error) -> Problem¶
-
Explains an operating-system error on
path(host.io, exit 4).
- pub fn gd_host::folders_of(paths: &[PathBuf], top: &Path) -> Vec<PathBuf>¶
-
Lists, once each and sorted, the folders that hold
pathsand those between them andtop(included): the folders whose names a publication adds or changes. A path not belowtopgives only its own folder.
- pub fn gd_host::is_stage_name(name: &str) -> bool¶
-
Reports whether
nameis oneStagegives a staging file:STAGE_PREFIX, ten digits, then nothing or one extension. Any other name, however close, is not ours.
- pub fn gd_host::publish(path: &Path, data: &[u8], force: bool) -> Result<(), Problem>¶
-
Writes
datatopaththrough a flushed staging file renamed over it, making the folders on its way. An existingpathis refused (host.output.exists) unlessforceis set; any failure leavespathunchanged.
- pub fn gd_host::remove_stages(dir: &Path)¶
-
Removes, in
dirand every folder below it, the staging files a stopped process (killed, or the machine lost power) left behind: regular files whose namesis_stage_nameaccepts. Everything else stays; a folder that cannot be listed is left as it is. The caller makes sure no stage belowdiris still in use.
- pub fn gd_host::sync_all(paths: &[PathBuf]) -> Result<(), Problem>¶
-
Flushes files and folders to storage, several at once, and returns the first that failed. A folder is flushed so the names in it are durable (skipped on Windows, which keeps them durable itself); a path that is gone or a link has nothing to flush.
- pub fn gd_host::sync_each(paths: &[PathBuf]) -> Result<(), Problem>¶
-
Flushes each path in turn on the calling thread, as
sync_alldoes with threads.
- pub fn gd_host::write_unsynced(path: &Path, data: &[u8]) -> Result<(), Problem>¶
-
Writes
dataaspublishdoes (replacingpath), but flushes nothing: a publication of many files writes them all, then makes them durable in one pass (sync_allof the files and theirfolders_of).
- pub fn gd_host::default_stack_budget(stack: usize) -> usize¶
-
The budget to use when none is asked for:
guidedoc::DEFAULT_STACK_BYTES, or less on a thread too small for it.
- pub fn gd_host::map_ordered<I, S, R>(threads: usize, items: I, init: impl Fn() -> S + Sync, work: impl Fn(&mut S, I::Item) -> R + Sync) -> Vec<R> where I: IntoIterator, I::IntoIter: Send, R: Send¶
-
Runs
workon every item ofitemsonthreadsworkers (throughrun_workers) and returns the results in the order ofitems, however the threads interleave. Each worker first makes its own state withinit(a workspace, a highlighter) and passes it toworkfor every item it takes; the state is dropped when the worker ends. A panic ininitorworkis raised again on the caller, asrun_workersdoes.
- pub fn gd_host::run_with_stack<R: Send>(bytes: usize, work: impl FnOnce() -> R + Send) -> R¶
-
Runs
workon a thread with a stack ofbytesand returns its result, so a command knows the stack its conversions run on; on the calling thread when no thread can be started. A panic inworkis raised again on the caller.
- pub fn gd_host::run_workers<F>(count: usize, work: F) where F: Fn(usize) + Sync¶
-
Runs
work(i)oncountthreads at once (ifrom 0), each with a stack ofWORKER_STACK_BYTES, and returns when all have ended;worktakes its share itself (an index taken atomically, for one). A thread that cannot start is left out; when none can,work(0)runs on the calling thread, so the work is always done. A panic in a worker is raised again on the caller, once every worker has ended, with its original payload.
- pub fn gd_host::stack_budget_limit(stack: usize) -> usize¶
-
The largest stack budget a thread with
stackbytes can hold: all but 2 MiB of headroom, and never less than half the stack. An 8 MiB thread holds 6 MiB.
Type Aliases
- pub type gd_host::OnRefusal = dyn Fn(&Refusal) -> RefusalChoice + Send + Sync¶
-
The policy a budget asks (at most one call at a time, while its other reservations wait). It must not reserve from the budget it is asked about.
Constants
- pub const gd_host::AVAILABLE_OVERRIDE: &str = "GUIDEDOG_AVAILABLE_MIB"¶
-
The environment variable that states the machine’s free memory in MiB, for machines whose own report misleads (
available_memory).
- pub const gd_host::DEFAULT_BUDGET: usize = 256 << 20¶
-
The budget
guidedog convertuses when none is given (256 MiB).
- pub const gd_host::CRASH_EXIT: i32 = 70¶
-
The exit status of a command that crashed: EX_SOFTWARE, which no other failure uses.
- pub const gd_host::ISSUE_TRACKER: &str¶
-
Where a crash is to be reported: the issue tracker of whoever distributes the build, set when it is built (
GUIDEDOG_ISSUE_TRACKER=https://...); „“ names none.
- pub const gd_host::MAX_SOURCE_BYTES: usize = 32 << 20¶
-
The default size limit of one input file (32 MiB).
- pub const gd_host::STAGE_PREFIX: &str = ".guidedog-stage-"¶
-
Begins the name of every staging file: then ten digits, then the destination’s extension (
.guidedog-stage-0123456789.html).
- pub const gd_host::WORKER_STACK_BYTES: usize = 8 << 20¶
-
The stack of every thread
run_workersandrun_with_stackstart (8 MiB, the main thread’s usual stack on Linux and macOS).