Guidedog マニュアル 1.0.0-beta.16
言語
このページの内容
Guidedog / ドキュメント 1.0.0-beta.16

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(&registry, &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 from Default.

Fields

pub input: &'a str

The input path, or "-" for standard input.

pub from: Format

The markup of the input.

pub to: Target

The artifact to publish.

pub output: &'a str

The output path, or "-" for standard output.

pub emit_typst: Option<&'a Path>

Where to publish the intermediate Typst source too, if anywhere.

pub force: bool

Replace existing outputs.

pub policy: Policy

The conversion’s trust decisions.

pub limits: Limits

The conversion’s bounds; their byte bounds are lowered to the budget.

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; reserve is 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_artifact did. Reports are kept whatever the outcome; exit is 0 on success, else the status the command ends with, explained by problem or by the error reports.

Fields

pub exit: i32

The process exit status.

pub reports: Vec<Report>

The conversion’s and Typst’s diagnostics, ready to render.

pub problem: Option<Problem>

The host failure, if one stopped the route.

pub delivered: Delivered

Where the artifact went.

pub struct gd_host::Budget

Bounds the bytes a build holds at once, shared by its threads (Budget is Sync).

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 new(limit: usize) -> Budget

Makes a budget of limit bytes that refuses what it cannot hold.

pub fn with_policy(limit: usize, on_refusal: impl Fn(&Refusal) -> RefusalChoice + Send + Sync + 'static) -> Budget

Makes a budget of limit bytes that asks on_refusal what 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.

pub fn last_refusal(&self) -> Option<Refusal>

What the budget held and was asked for when it last refused, if it has.

pub fn join(&self) -> Unit<'_>

Counts a unit of work that runs at once with others until the returned guard drops (see Budget). Borrows the budget for the guard’s life.

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 new(budget: &'b Budget) -> Ledger<'b>

Makes a ledger charging budget, which it borrows.

pub fn unbounded() -> Ledger<'static>

Makes a ledger that counts nothing and refuses nothing.

pub fn budget(&self) -> Option<&'b Budget>

The budget it charges, if any.

pub fn charge(&self, bytes: usize) -> bool

Reserves bytes, waiting as Budget describes. Returns false, reserving nothing, when the budget refuses; refused then tells the bytes asked for.

pub fn discharge(&self, bytes: usize)

Returns bytes the 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 /path in include and literalinclude; 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>
pub fn new<P: AsRef<Path>>(roots: &[P]) -> Files<'static>

Serves files below roots, resolved now (canonical_roots), up to MAX_SOURCE_BYTES each, charging nothing.

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 / below project.

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 text: String

The text, UTF-8 checked, without a byte order mark.

pub canonical: String

The absolute, resolved path, or "-" for standard input.

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 kind: PathKind

What it names; a symbolic link is PathKind::Link.

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::report to 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 path: String

The path the problem concerns, as given; may be empty.

pub message: String

The plain explanation.

pub hint: String

How to fix it.

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
pub fn new(code: &'static str, title: &'static str, path: &str, message: impl Into<String>, hint: impl Into<String>, exit: i32) -> Problem

Makes a problem from its parts; path is copied.

pub fn report(&self) -> Report

The problem as an error report without a position, for gd_report::render_text and render_json. Copies the problem’s text.

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 with host.io.

pub fn path(&self) -> &Path

The staging file’s path, for a producer to write to.

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) unless force is 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 reserve capacity bytes together and run at most slots at once (0 counts as 1).

pub fn job_count(&self) -> usize

The number of jobs.

pub fn phase(&self, job: usize) -> JobPhase

Where job is. Panics when job is 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 job may start now: the guard of start. room is 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 job as running. Panics when it may not start, whatever room says: the caller asks Schedule::next or Schedule::may_start first.

pub fn finish(&mut self, job: usize, succeeded: bool)

Marks the running job as 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 fn first_failure(&self) -> Option<usize>

The first job that failed, in plan order.

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 reports describe the last run only.

Implementations

impl Session
pub fn new() -> Session

Makes a session with an empty workspace; it allocates nothing until used.

pub fn run(&mut self, registry: &Registry, request: &Request<'_>) -> Result<&str, Fail>

Converts request with registry: 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, reports explains it.

pub fn read(&mut self, reader: &Reader, request: &Request<'_>) -> Result<Document<'_>, Fail>

Reads request’s source with reader without rendering, then runs request.passes over 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.

pub fn workspace(&self) -> &Workspace

The workspace, for the source table, source map, and raw diagnostics.

pub fn workspace_mut(&mut self) -> &mut Workspace

The workspace, for the engine’s staged calls (check_render, load_object).

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_artifact reads.

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

impl Format
pub fn reader(self) -> Option<&'static str>

The id of the reader of the format; None for native Typst, which is compiled.

pub enum gd_host::Target

The artifact convert_artifact publishes.

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

impl Target
pub fn renderer(self) -> &'static str

The id of the renderer that writes the target (PDF goes through Typst).

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.

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.

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 with registry (the readers and renderers Format::reader and Target::renderer name) 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_OVERRIDE in MiB when set, else what the system reports (GDS 0020). On Linux that is MemAvailable from /proc/meminfo, lowered to what the process’s control group may still use (cgroup_room); on macOS, the free, speculative and inactive pages that vm_stat counts; on Windows, ullAvailPhys of GlobalMemoryStatusEx. None when 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 for need bytes while the budget held used of limit, on a machine with available bytes 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 budget held and was asked for when it last refused (need when 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 budget refused (host.budget, exit 3): what needed bytes, 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 available free 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

limits with the byte bounds of one conversion (text pool, output, included sources) lowered to budget bytes, so no single conversion is allowed more than the whole budget. A budget of 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: VmHWM from /proc/self/status on Linux, ru_maxrss of getrusage on macOS, and the peak working set on Windows; None elsewhere 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 available known and smaller, the budget is capped to fitting_budget, or is what is needed in steps of 16 MiB when even that does not fit; fits is then false.

pub fn gd_host::canonical_roots<P: AsRef<Path>>(roots: &[P]) -> Vec<PathBuf>

Resolves roots to absolute paths with every link followed, as confined compares 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 canonical roots: 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 confined accepts path, 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 roots that path is written below (or is), comparing whole components and following no link; confined is the check that follows them.

pub fn gd_host::catch_crash(command: impl FnOnce() -> i32) -> i32

Runs command and returns its exit status; a panic that unwinds out of it prints the crash report to standard error and returns CRASH_EXIT.

pub fn gd_host::crash_report(cause: &str) -> String

The whole report for cause, from the parts install_crash_reporter prepared.

pub fn gd_host::install_crash_reporter(args: &[String], version: &str)

Prepares the crash report for the command line args (the program name first) and version (what guidedog --version prints), 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 ws holds 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 as display_path shows it, and the line, columns, and excerpt of its span. The report copies what it needs and outlives ws.

pub fn gd_host::describe_all(ws: &Workspace) -> Vec<Report>

Describes every diagnostic the last conversion in ws reported, 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

name relative to the working directory when that reads shorter (not three or more folders above it), and name itself 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 each until 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 limit bytes whole, charging its size to ledger before 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 most limit bytes, checks that it is UTF-8 and drops a leading byte order mark. Fails with host.io, host.file-type, host.limit.source, or host.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 limit bytes, probing one byte past the limit: neither an endless pipe nor a growing file can force an unbounded allocation. name names the stream in problems.

pub fn gd_host::same_contents(path: &Path, data: &[u8]) -> bool

Reports whether the file at path holds exactly data, 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 renameat2 with RENAME_EXCHANGE, macOS’s renamex_np with RENAME_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); None when nothing is, or where the system gives no inode (Windows).

Makes to name the same file as from: a hard link, or a copy where the file system cannot link (FAT, some network shares), which Ok(true) reports and the caller must flush. A symbolic link (kind is PathKind::Link) is made again, to the same target. An existing to is 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; None when 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 at path is 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::Request polls (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_interrupt called) 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 paths and those between them and top (included): the folders whose names a publication adds or changes. A path not below top gives only its own folder.

pub fn gd_host::is_stage_name(name: &str) -> bool

Reports whether name is one Stage gives 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 data to path through a flushed staging file renamed over it, making the folders on its way. An existing path is refused (host.output.exists) unless force is set; any failure leaves path unchanged.

pub fn gd_host::remove_stages(dir: &Path)

Removes, in dir and every folder below it, the staging files a stopped process (killed, or the machine lost power) left behind: regular files whose names is_stage_name accepts. Everything else stays; a folder that cannot be listed is left as it is. The caller makes sure no stage below dir is 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_all does with threads.

pub fn gd_host::write_unsynced(path: &Path, data: &[u8]) -> Result<(), Problem>

Writes data as publish does (replacing path), but flushes nothing: a publication of many files writes them all, then makes them durable in one pass (sync_all of the files and their folders_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 work on every item of items on threads workers (through run_workers) and returns the results in the order of items, however the threads interleave. Each worker first makes its own state with init (a workspace, a highlighter) and passes it to work for every item it takes; the state is dropped when the worker ends. A panic in init or work is raised again on the caller, as run_workers does.

pub fn gd_host::run_with_stack<R: Send>(bytes: usize, work: impl FnOnce() -> R + Send) -> R

Runs work on a thread with a stack of bytes and 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 in work is raised again on the caller.

pub fn gd_host::run_workers<F>(count: usize, work: F) where F: Fn(usize) + Sync

Runs work(i) on count threads at once (i from 0), each with a stack of WORKER_STACK_BYTES, and returns when all have ended; work takes 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 stack bytes 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 convert uses 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_workers and run_with_stack start (8 MiB, the main thread’s usual stack on Linux and macOS).