gd_plugins ========== .. rust:crate:: gd_plugins :synopsis: Typed build plugins (GDS 0010) and publishers (GDS 0009), linked into an application or run as installed programs behind a bounded JSON Lines protocol. Typed build plugins (GDS 0010) and publishers (GDS 0009), linked into an application or run as installed programs behind a bounded JSON Lines protocol. A :rust:struct:`Plugin ` is either build hooks (:rust:trait:`BuildPlugin `: source text, complete HTML pages, generated static assets) or a :rust:trait:`Publisher ` (sends a finished site to a destination), never both. A normal build never invokes a publisher. .. code-block:: text BuildPlugin load_plugin -> PluginSession process_source / process_html / collect_assets; Drop unloads Publisher load_publisher -> PublisherSession plan / publish / status / recover Snapshot snapshot(dir) a frozen, checked copy of a built site; Drop removes it Plugin authors implement a trait and, for an installed program, serve it with one call, :rust:fn:`serve ` (build hooks) or :rust:fn:`serve_publisher `: .. code-block:: rust use std::borrow::Cow; use gd_plugins::{BuildPlugin, Hooks, PluginInfo, Problem, SourceInput}; #[derive(Clone, Default)] struct Shout; impl BuildPlugin for Shout { fn info(&self) -> PluginInfo { PluginInfo::new("shout", "Shout", "1.0.0", Hooks { source: true, ..Hooks::NONE }) } fn process_source<'a>(&mut self, input: &SourceInput<'a>) -> Result, Problem> { Ok(Cow::Owned(input.text.to_uppercase())) } } fn main() -> std::process::ExitCode { gd_plugins::serve(Shout) } Installed programs are recorded in the machine registry (:rust:fn:`read_machine `, :rust:fn:`register `, :rust:fn:`unregister `), pinned by SHA-256, and reached through :rust:fn:`process_plugin ` and :rust:fn:`process_publisher `. Nothing here discovers, downloads or starts a program by itself. Failures are :rust:struct:`Problem `\ s with hints, never panics. .. rubric:: Modules - :rust:mod:`gd_plugins::files` -- Private folders and files, and files replaced in one step: what a host or a publisher needs to keep state (a registry, tokens, a frozen site) that only its user may read. .. rubric:: Structs .. rust:struct:: pub struct Asset One generated file: a relative, portable path such as ``css/badge.css``, and bytes. .. rubric:: Fields .. rust:field:: pub path: String The path below ``_static/plugins/ID/``. .. rust:field:: pub data: Vec The file's contents. .. rubric:: Implementations .. rust:impl:: impl Asset :noindex: :for: Asset .. rust:method:: pub fn new(path: &str, data: impl Into>) -> Asset Makes an asset from a path and bytes. .. rust:struct:: pub struct Hooks Which build hooks a plugin offers. .. rubric:: Fields .. rust:field:: pub source: bool :rust:fn:`BuildPlugin::process_source `. .. rust:field:: pub html: bool :rust:fn:`BuildPlugin::process_html `. .. rust:field:: pub assets: bool :rust:fn:`BuildPlugin::collect_assets `. .. rubric:: Implementations .. rust:impl:: impl Hooks :noindex: :for: Hooks .. rust:associatedconst:: pub const NONE: Hooks No hooks. .. rust:associatedconst:: pub const ALL: Hooks = Hooks { source: true, html: true, assets: true } Every hook. .. rust:method:: pub fn is_any(self) -> bool Whether at least one hook is offered. .. rust:method:: pub fn names(self) -> impl Iterator The protocol names of the offered hooks, in the order source, html, assets. .. rust:struct:: pub struct HtmlInput<'a> :attributes: #[non_exhaustive] One complete rendered HTML page before staging, borrowed for the call. Hosts make it; it is ``#[non_exhaustive]`` so later fields are not a breaking change. Use the constructor, or ``Default`` and field assignment. .. rubric:: Fields .. rust:field:: pub path: &'a str The output page's path. .. rust:field:: pub docname: &'a str The document's name in the project. .. rust:field:: pub language: &'a str The build's language. .. rust:field:: pub text: &'a str The complete page. .. rust:field:: pub assets_url: &'a str The URL of this plugin's assets relative to the page, ending in ``/``. .. rubric:: Implementations .. rust:impl:: impl<'a> HtmlInput<'a> :noindex: :for: HtmlInput<'a> .. rust:method:: pub fn new(path: &'a str, docname: &'a str, language: &'a str, text: &'a str, assets_url: &'a str) -> HtmlInput<'a> Describes one rendered page; ``assets_url`` is relative to it and ends in ``/``. .. rust:struct:: pub struct LoadContext<'a> What :rust:fn:`BuildPlugin::load ` gets: the session's options, and the dependency files and cache key that identify what it loaded. Both only grow: helpers append the fingerprints of the bytes they read, and nothing can erase them. .. rubric:: Implementations .. rust:impl:: impl<'a> LoadContext<'a> :noindex: :for: LoadContext<'a> .. rust:method:: pub fn options(&self) -> &PluginOptions The session's options. .. rust:method:: pub fn dependencies(&self) -> &[String] The dependency files declared so far. .. rust:method:: pub fn cache_key(&self) -> &str The cache key so far. .. rust:method:: pub fn add_cache_key(&mut self, text: &str) Appends ``text`` to the cache key: a fingerprint of anything loaded that is not a declared file, such as a selected environment value. .. rust:method:: pub fn declare_dependency(&mut self, path: &str) -> Result<(), Problem> Declares a file read by other means; the host hashes it before reusing output. Fails beyond 256 files or for an empty, overlong or NUL-holding path. .. rust:method:: pub fn read_config(&mut self) -> Result Reads the configuration file (``options.config``, at most 1 MiB of UTF-8), declares it and adds its fingerprint to the cache key. .. rust:method:: pub fn read_file(&mut self, path: &str) -> Result Reads a UTF-8 load input of at most 8 MiB, declares it and adds its fingerprint to the cache key. A relative path resolves from ``options.project``. Fingerprinting the bytes actually read keeps old state from pairing with a newer file. .. rust:struct:: pub struct PluginInfo A build plugin's identity: an ID (see :rust:fn:`crate::is_valid_id `), a display name of at most 256 bytes, a product version of at most 64 bytes, the interface version it was built against, and its hooks. .. rubric:: Fields .. rust:field:: pub id: String The ID a project selects in ``conf.toml``. .. rust:field:: pub name: String The name people see. .. rust:field:: pub version: String The plugin's own release version. .. rust:field:: pub api: Version The build-plugin interface version, normally :rust:const:`PLUGIN_API_VERSION `. .. rust:field:: pub hooks: Hooks The hooks it offers. .. rubric:: Implementations .. rust:impl:: impl PluginInfo :noindex: :for: PluginInfo .. rust:method:: pub fn new(id: &str, name: &str, version: &str, hooks: Hooks) -> PluginInfo Describes a plugin built against :rust:const:`PLUGIN_API_VERSION `. .. rust:struct:: pub struct PluginOptions :attributes: #[non_exhaustive] A build session's settings. Paths are at most :rust:const:`MAX_PATH ` bytes; builder and language names at most 64. Hosts make it; it is ``#[non_exhaustive]`` so later fields are not a breaking change. Use the constructor, or ``Default`` and field assignment. .. rubric:: Fields .. rust:field:: pub config: String The plugin's configuration file, from ``[plugin_configs]``; may be empty. .. rust:field:: pub project: String The project folder; relative input paths resolve from it. .. rust:field:: pub builder: String The builder, such as ``html``. .. rust:field:: pub language: String The build's language. .. rust:field:: pub request_timeout: Duration Bounds each whole request to an installed program; zero means one minute. Linked plugins have no forced deadline. .. rust:field:: pub cancel: Cancel Stops the build between and during requests. .. rubric:: Implementations .. rust:impl:: impl PluginOptions :noindex: :for: PluginOptions .. rust:method:: pub fn new(config: &str, project: &str, builder: &str, language: &str) -> PluginOptions Options for one build: the plugin's configuration file, the project folder, the builder and the language; the default timeout and no cancellation. .. rust:struct:: pub struct SourceInput<'a> :attributes: #[non_exhaustive] One complete primary document before parsing, borrowed for the call. Includes are read by the engine later and do not pass through a source hook. Hosts make it; it is ``#[non_exhaustive]`` so later fields are not a breaking change. Use the constructor, or ``Default`` and field assignment. .. rubric:: Fields .. rust:field:: pub path: &'a str The document's file path. .. rust:field:: pub docname: &'a str The document's name in the project, such as ``guide/install``. .. rust:field:: pub format: SourceFormat Its markup. .. rust:field:: pub language: &'a str The build's language, such as ``en``. .. rust:field:: pub text: &'a str The complete text. .. rubric:: Implementations .. rust:impl:: impl<'a> SourceInput<'a> :noindex: :for: SourceInput<'a> .. rust:method:: pub fn new(path: &'a str, docname: &'a str, format: SourceFormat, language: &'a str, text: &'a str) -> SourceInput<'a> Describes one primary document. .. rust:struct:: pub struct PluginSession One loaded build plugin, private to one build. It owns copied options, the plugin's state, and the dependency files and cache key that identify what was loaded. Every hook call checks its input and the plugin's reply. Dropping the session unloads the plugin (and ends its program, for an installed one). **Concurrency.** A host opens one session per selected plugin per build; its state, cache key and dependencies belong to that build. Hooks take ``&mut self``, so calls are serialized: call from one thread, or put the sessions in a ``Mutex`` shared by the reading workers (the session is ``Send``, so ``Mutex`` is ``Sync``). A plugin therefore never needs synchronization of its own. .. code-block:: rust fn shared_by_workers() {} shared_by_workers::>>(); shared_by_workers::(); .. rubric:: Implementations .. rust:impl:: impl PluginSession :noindex: :for: PluginSession .. rust:method:: pub fn load(plugin: &Plugin, options: &PluginOptions) -> Result Starts a fresh plugin value and loads it with a copy of ``options``. Fails for a publisher, invalid options, a load problem, or cancellation; a failed load is unloaded before this returns. .. rust:method:: pub fn info(&self) -> &PluginInfo The plugin's identity and hooks, as read before load. .. rust:method:: pub fn options(&self) -> &PluginOptions The options the session was loaded with. .. rust:method:: pub fn dependencies(&self) -> &[String] The files load read; the host hashes them before reusing output. .. rust:method:: pub fn cache_key(&self) -> &str The fingerprint of everything else load used. .. rust:method:: pub fn process_source<'a>(&mut self, input: &SourceInput<'a>) -> Result, Problem> Runs the source hook on one primary document. Without a source hook the text is returned unchanged. Fails on input or output over 8 MiB, overlong names, a hook problem (with the plugin and stage named), or cancellation. .. rust:method:: pub fn process_html<'a>(&mut self, input: &HtmlInput<'a>) -> Result, Problem> Runs the HTML hook on one complete rendered page, as :rust:fn:`PluginSession::process_source ` does for source text. .. rust:method:: pub fn collect_assets(&mut self) -> Result, Problem> Collects the plugin's generated files, checked: at most 256 files and 16 MiB, portable relative paths, no duplicates ignoring case, no file used as a folder. The host stages them under ``_static/plugins/ID/``. .. rubric:: Trait Implementations .. rust:impl:: impl std::fmt::Debug for PluginSession :noindex: :for: PluginSession :trait: std::fmt::Debug .. rust:method:: fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result :noindex: .. rust:struct:: pub struct Cancel A cancellation request a caller can raise while a plugin works. The default never cancels. Clones share one probe; the SDK polls it between and during requests. Cancellation asks a plugin to stop; it cannot undo a write a target accepted. .. rubric:: Implementations .. rust:impl:: impl Cancel :noindex: :for: Cancel .. rust:method:: pub fn from_flag(flag: Arc) -> Cancel A probe that reads ``flag``, which a signal handler or another thread may set. .. rust:method:: pub fn from_fn(probe: impl Fn() -> bool + Send + Sync + 'static) -> Cancel A probe that calls ``probe``; it must be cheap, as it is polled often. .. rust:method:: pub fn is_cancelled(&self) -> bool Whether cancellation has been requested. .. rubric:: Trait Implementations .. rust:impl:: impl fmt::Debug for Cancel :noindex: :for: Cancel :trait: fmt::Debug .. rust:method:: fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result :noindex: .. rust:struct:: pub struct BuildRequest What a contributed command asks the host to build: a Guidedog project with one builder into a folder, with settings overridden as ``-D`` does, the site's public URL, and warnings as errors when ``strict``. The default builds HTML. .. rubric:: Fields .. rust:field:: pub project: PathBuf The project folder (where conf.toml is). .. rust:field:: pub output: PathBuf The folder the output is written to. .. rust:field:: pub builder: String The builder, as ``guidedog build`` names it (``html``, ``dirhtml``, ``singlehtml``, ``pdf``, ``text``); empty for ``html``. .. rust:field:: pub overrides: Vec Settings that replace conf.toml's, each ``name=value`` as ``-D`` takes them. .. rust:field:: pub base_url: String The site's public URL (``html_baseurl``); empty to keep the project's. .. rust:field:: pub strict: bool Build with warnings as errors. .. rust:field:: pub now: String Fixed RFC 3339 publication clock; empty uses the host's build clock. .. rust:field:: pub preview: bool Include withheld pages in a separate preview publication. .. rust:struct:: pub struct CommandContext<'h> Everything a contributed command may use: the host's streams, questions to the person, the host's build, and plain facts about the run in public fields. .. rubric:: Fields .. rust:field:: pub dir: PathBuf The working folder the command was started in. .. rust:field:: pub config: String The plugin's configuration file, when the project names one (conf.toml's ``plugin_configs``); empty for the plugin's own default. .. rust:field:: pub host_program: String The host program, for a command that must start it (such as a watch loop). .. rust:field:: pub interactive: bool A person may be asked: input and error output are a terminal. .. rust:field:: pub color: bool The person asked for colors on the terminal. .. rust:field:: pub json: bool The person asked for JSON reports (``--diagnostics=json``). .. rust:field:: pub quiet: bool The person asked for no success messages (``-q``). .. rust:field:: pub cancel: Cancel Set when the person asks the command to stop (Ctrl+C). .. rubric:: Implementations .. rust:impl:: impl<'h> CommandContext<'h> :noindex: :for: CommandContext<'h> .. rust:method:: pub fn new(host: &'h mut dyn CommandHost) -> CommandContext<'h> A context over ``host``, in the current folder, not interactive, with no colors, no configuration and no cancellation; the host sets the fields it knows. .. rust:method:: pub fn streams(&mut self) -> (&mut dyn Write, &mut dyn Write) The host's standard output and standard error. .. rust:method:: pub fn print(&mut self, text: &str) Writes ``text`` to standard output. A closed output is not the command's problem. .. rust:method:: pub fn eprint(&mut self, text: &str) Writes ``text`` to standard error. .. rust:method:: pub fn flush(&mut self) Flushes both streams, before another program writes to the same terminal. .. rust:method:: pub fn ask(&mut self, question: &str) -> Option Shows ``question`` on standard error and returns the person's answer, trimmed; ``None`` when no person may be asked or the input ended. .. rust:method:: pub fn confirm(&mut self, question: &str) -> bool Asks a yes-or-no question; anything but ``y`` or ``yes``, or no person, is no. .. rust:method:: pub fn build_project(&mut self, request: &BuildRequest) -> Result<(), Problem> Has the host build ``request``'s project; see :rust:fn:`CommandHost::build_project `. .. rubric:: Trait Implementations .. rust:impl:: impl fmt::Debug for CommandContext<'_> :noindex: :for: CommandContext<'_> :trait: fmt::Debug .. rust:method:: fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result :noindex: .. rust:struct:: pub struct CommandInfo A command a plugin adds to the host's command line. Its ``path`` is the words that name it: ``["pages", "workflow"]`` is ``guidedog pages workflow``, and ``["publish", "pages"]`` is the target ``pages`` of ``guidedog publish``. .. rubric:: Fields .. rust:field:: pub path: Vec The words that name the command: 1 to 4 lowercase words. .. rust:field:: pub summary: String One line saying what it does, for the host's command list. .. rust:field:: pub help: String What ``--help`` shows after the usage line: plain text, lines of at most 80 characters. .. rust:field:: pub options: Vec The options it takes, for its help and the host's suggestions. .. rubric:: Implementations .. rust:impl:: impl CommandInfo :noindex: :for: CommandInfo .. rust:method:: pub fn new(name: &str, summary: &str) -> CommandInfo A command named by the words of ``name`` (``"pages workflow"``), with its summary. .. rust:method:: pub fn with_help(mut self, help: &str) -> CommandInfo The command with ``help`` as its help text. .. rust:method:: pub fn with_option(mut self, option: CommandOption) -> CommandInfo The command with ``option`` added to its options. .. rust:method:: pub fn name(&self) -> String The command's name: its words joined by spaces, such as ``pages workflow``. .. rust:struct:: pub struct CommandOption An option a contributed command takes, as its help shows it. .. rubric:: Fields .. rust:field:: pub name: String The option as written, such as ``--write`` or ``-o``. .. rust:field:: pub value: String The placeholder of its value, such as ``DIR``; empty for a switch. .. rust:field:: pub summary: String One line saying what it does. .. rubric:: Implementations .. rust:impl:: impl CommandOption :noindex: :for: CommandOption .. rust:method:: pub fn switch(name: &str, summary: &str) -> CommandOption A switch, such as ``--write``. .. rust:method:: pub fn with_value(name: &str, value: &str, summary: &str) -> CommandOption An option that takes a value, such as ``--project DIR``. .. rust:method:: pub fn takes_value(&self) -> bool Whether the option takes a value. .. rust:struct:: pub struct Machine The registry's entries. .. rubric:: Fields .. rust:field:: pub entries: Vec Every registered program, in registration order. .. rubric:: Implementations .. rust:impl:: impl Machine :noindex: :for: Machine .. rust:method:: pub fn find(&self, id: &str) -> Option<&MachineEntry> The entry with the ID ``id``. .. rust:struct:: pub struct MachineEntry :attributes: #[non_exhaustive] One registered program, as :rust:fn:`inspect_entry ` describes it and the registry keeps it. .. rubric:: Fields .. rust:field:: pub id: String The plugin's ID. .. rust:field:: pub name: String Its display name. .. rust:field:: pub version: String Its product version. .. rust:field:: pub path: String The program's absolute path. .. rust:field:: pub sha256: String The program's SHA-256 in hexadecimal. .. rust:field:: pub protocol: Version The protocol version selected when it was registered. .. rust:field:: pub capabilities: Capabilities A publisher's optional operations. .. rust:field:: pub registered: String The date it was registered, ``YYYY-MM-DD``. .. rust:field:: pub protocol_name: String :rust:const:`BUILD_PROTOCOL_NAME ` for a build plugin; empty for a publisher. .. rust:field:: pub hooks: Vec A build plugin's hook names; empty for a publisher. .. rust:field:: pub commands: Vec The commands the program contributes to the command line; empty for none. .. rust:field:: pub command_protocol: Version The command protocol version selected when it was registered; ``0.0`` when it contributes no command. .. rubric:: Implementations .. rust:impl:: impl MachineEntry :noindex: :for: MachineEntry .. rust:method:: pub fn is_build(&self) -> bool Whether the entry is a build plugin's. .. rust:struct:: pub struct Problem(_) A failure: a stable code (``"pages.credential"``), a title, the path or name it concerns, what went wrong, a hint that says what to do, and the exit status a command returns for it (always nonzero for a real problem). Exit statuses beyond 0 are 1 (failed, nothing published), 2 (usage or configuration), 3 (memory or a limit), 4 (files or processes), :rust:const:`EXIT_ACCEPTED `, :rust:const:`EXIT_UNKNOWN ` and 130 (cancelled). The fields live in a :rust:struct:`ProblemData ` box, so ``Result`` stays one pointer wide; read and write them directly (``p.code``, ``p.exit = 2``) through ``Deref``. .. rubric:: Implementations .. rust:impl:: impl Problem :noindex: :for: Problem .. rust:method:: pub fn new(code: &str, title: &str, message: &str) -> Problem Starts a problem with exit status 1 and no path or hint; chain :rust:fn:`Problem::hint `, :rust:fn:`Problem::path ` and :rust:fn:`Problem::exit ` to complete it. .. rust:method:: pub fn hint(mut self, hint: &str) -> Problem Sets the hint and returns the problem, for chaining. .. rust:method:: pub fn path(mut self, path: &str) -> Problem Sets the path the problem concerns and returns it, for chaining. .. rust:method:: pub fn exit(mut self, exit: i32) -> Problem Sets the exit status and returns the problem, for chaining. .. rust:method:: pub fn memory() -> Problem ``plugins.memory`` (exit 3): memory, or a buffer driven by input size, was refused. .. rust:method:: pub fn report(&self) -> Report Converts the problem into an Elm-style report for ``gd_report::render_text``. .. rubric:: Trait Implementations .. rust:impl:: impl std::ops::Deref for Problem :noindex: :for: Problem :trait: std::ops::Deref .. rust:associatedtype:: type Target = ProblemData :noindex: .. rust:method:: fn deref(&self) -> &ProblemData :noindex: .. rust:impl:: impl std::ops::DerefMut for Problem :noindex: :for: Problem :trait: std::ops::DerefMut .. rust:method:: fn deref_mut(&mut self) -> &mut ProblemData :noindex: .. rust:impl:: impl fmt::Display for Problem :noindex: :for: Problem :trait: fmt::Display .. rust:method:: fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result :noindex: .. rust:impl:: impl std::error::Error for Problem :noindex: :for: Problem :trait: std::error::Error .. rust:impl:: impl From for Problem :noindex: :for: Problem :trait: From .. rust:method:: fn from(data: ProblemData) -> Problem :noindex: .. rust:struct:: pub struct ProblemData The fields of a :rust:struct:`Problem `. Build one with struct-update syntax and convert it with ``.into()``, or start from :rust:fn:`Problem::new `. .. rubric:: Fields .. rust:field:: pub code: String A stable identifier such as ``"plugins.timeout"``. .. rust:field:: pub title: String A short sentence naming what failed. .. rust:field:: pub path: String The path or name the problem concerns; may be empty. .. rust:field:: pub message: String The plain explanation. .. rust:field:: pub hint: String What to do about it. .. rust:field:: pub exit: i32 The exit status a command returns for this problem. .. rust:struct:: pub struct Capabilities A publisher's optional operations. .. rubric:: Fields .. rust:field:: pub status: bool :rust:fn:`Publisher::status `. .. rust:field:: pub recover: bool :rust:fn:`Publisher::recover `. .. rubric:: Implementations .. rust:impl:: impl Capabilities :noindex: :for: Capabilities .. rust:method:: pub fn names(self) -> impl Iterator The protocol names of the capabilities, in the order status, recover. .. rust:method:: pub fn from_names<'a>(names: impl IntoIterator) -> Capabilities The capabilities ``names`` lists; unknown names are ignored. .. rust:method:: pub fn is_subset_of(self, other: Capabilities) -> bool Whether every capability of ``self`` is also in ``other``. .. rust:struct:: pub struct Change One file publishing adds, changes or removes. .. rubric:: Fields .. rust:field:: pub path: String The file's path in the site. .. rust:field:: pub kind: ChangeKind What happens to it. .. rust:struct:: pub struct LoadOptions :attributes: #[non_exhaustive] A publisher session's settings. The default is a real (not dry) run with the publisher's own wait and a five-minute request limit for programs. It is ``#[non_exhaustive]``: use :rust:fn:`LoadOptions::new ` or ``Default``, then assign fields. .. rubric:: Fields .. rust:field:: pub config: String The publisher's configuration file, such as ``pages.toml``. .. rust:field:: pub dry_run: bool The session only plans: it never writes to the target. .. rust:field:: pub wait_seconds: i64 How long publish waits for a deployment to be confirmed: 0, the publisher's default; below 0, not at all (the outcome is then at most ``Accepted``). .. rust:field:: pub cancel: Cancel Asks the publisher to stop; it cannot undo a write the target accepted. .. rust:field:: pub request_timeout: Duration Bounds each whole exchange with a program; zero means five minutes. .. rubric:: Implementations .. rust:impl:: impl LoadOptions :noindex: :for: LoadOptions .. rust:method:: pub fn new(config: &str) -> LoadOptions Options for a real run with the configuration file ``config``. .. rust:struct:: pub struct Loaded What :rust:fn:`Publisher::load ` returns: the source, and the target described for people, such as ``"github.com/owner/repo, branch gh-pages"``. .. rubric:: Fields .. rust:field:: pub source: Source What to publish. .. rust:field:: pub target: String Where it goes. .. rust:struct:: pub struct Outcome The outcome of publish, status or recover: a state, the operation's ID, the generation it concerns (hexadecimal), the URL the site is seen at, and, unless the outcome is verified, a problem that explains it. .. rubric:: Fields .. rust:field:: pub state: State Where the publication stands. .. rust:field:: pub operation: String The operation's ID, for status and recover. .. rust:field:: pub generation: String The generation's digest in hexadecimal. .. rust:field:: pub url: String Where the site is seen. .. rust:field:: pub problem: Option Why the outcome is not verified. .. rubric:: Implementations .. rust:impl:: impl Outcome :noindex: :for: Outcome .. rust:method:: pub fn failed(problem: Problem) -> Outcome A ``Failed`` outcome with ``problem``. .. rust:method:: pub fn exit_status(&self) -> i32 The exit status a command returns: 0 when verified (``Live``, ``Unchanged``), :rust:const:`EXIT_ACCEPTED ` for ``Accepted`` or ``Pending``, :rust:const:`EXIT_UNKNOWN ` for ``Unknown``, and the problem's status (at least 1) otherwise. .. rust:struct:: pub struct Plan What publishing a snapshot to a session's target would do. A plan is published only by the session that made it, with the snapshot it was made from. .. rubric:: Fields .. rust:field:: pub target: String The target, for people. .. rust:field:: pub baseline: String The target state compared with, as the publisher names it; empty for none. .. rust:field:: pub unchanged: bool The target already holds the generation; ``changes`` is then empty. .. rust:field:: pub changes: Vec The changes, in the publisher's order. .. rust:field:: pub summary: String What a person should see first, such as the account. .. rust:field:: pub data: Option> The publisher's own data for publish; see :rust:fn:`Plan::data_as `. .. rubric:: Implementations .. rust:impl:: impl Plan :noindex: :for: Plan .. rust:method:: pub fn generation(&self) -> [u8; 32] The generation the plan publishes: the snapshot's digest. .. rust:method:: pub fn generation_hex(&self) -> String The generation in lowercase hexadecimal. .. rust:method:: pub fn id(&self) -> &str The plan's name in its session, for the process protocol; may be empty. .. rust:method:: pub fn data_as(&self) -> Option<&T> The publisher's data, if it is a ``T``. .. rubric:: Trait Implementations .. rust:impl:: impl fmt::Debug for Plan :noindex: :for: Plan :trait: fmt::Debug .. rust:method:: fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result :noindex: .. rust:struct:: pub struct PublisherInfo A publisher's identity: ID, name, product version, the interface version it was built against, and its optional operations. .. rubric:: Fields .. rust:field:: pub id: String The ID users select, such as ``pages``. .. rust:field:: pub name: String The name people see. .. rust:field:: pub version: String The publisher's own release version. .. rust:field:: pub api: Version The publisher interface version, normally :rust:const:`API_VERSION `. .. rust:field:: pub capabilities: Capabilities Its optional operations. .. rubric:: Implementations .. rust:impl:: impl PublisherInfo :noindex: :for: PublisherInfo .. rust:method:: pub fn new(id: &str, name: &str, version: &str, capabilities: Capabilities) -> PublisherInfo Describes a publisher built against :rust:const:`API_VERSION `. .. rust:struct:: pub struct Source What a session publishes: a Guidedog project to build as HTML (with warnings as errors when ``strict``), or a folder holding a site already built; exactly one of ``project`` and ``site`` is set. ``base_url`` is where the site is seen. .. rubric:: Fields .. rust:field:: pub project: String A project folder to build. .. rust:field:: pub site: String A built site's folder. .. rust:field:: pub base_url: String The site's public URL. .. rust:field:: pub strict: bool Build with warnings as errors. .. rust:struct:: pub struct Plugin A plugin an application offers: build hooks or a publisher, never both. It makes a fresh plugin value for every session, so sessions never share state. .. rubric:: Implementations .. rust:impl:: impl Plugin :noindex: :for: Plugin .. rust:method:: pub fn build(prototype: P) -> Plugin Offers build hooks. Each session starts from a clone of ``prototype``, the unloaded plugin, and its ``info`` is read once, here. .. rust:method:: pub fn publisher(prototype: P) -> Plugin Offers a publisher. Each session starts from a clone of ``prototype``. .. rust:method:: pub fn commands(&self) -> &[CommandInfo] The commands the plugin adds to the host's command line, in its order. .. rust:method:: pub fn run_command(&self, ctx: &mut CommandContext<'_>, name: &str, args: &[String]) -> Result Runs the contributed command ``name`` (its words joined by spaces, such as ``pages workflow``) with ``args``, the words after its name, and returns its exit status. A linked plugin runs it on a fresh value; an installed program is started with :rust:const:`crate::COMMAND_FLAG ` on the host's terminal. Fails when the plugin contributes no such command, or the command or its program fails. .. rust:method:: pub fn id(&self) -> &str The plugin's ID. .. rust:method:: pub fn build_info(&self) -> Option<&PluginInfo> The build plugin's identity and hooks; ``None`` for a publisher. .. rust:method:: pub fn publisher_info(&self) -> Option<&PublisherInfo> The publisher's identity and capabilities; ``None`` for build hooks. .. rust:method:: pub fn is_publisher(&self) -> bool Whether this plugin is a publisher. .. rust:method:: pub fn executable(&self) -> &str The installed program it runs, for :rust:fn:`crate::process_plugin ` and :rust:fn:`crate::process_publisher `; empty for a linked plugin. .. rust:method:: pub fn identity(&self, host_build: &str) -> String The plugin's identity for build cache keys: what must change for outputs it produced to be rebuilt. For an installed program it is the registered program's SHA-256, which pins its exact code. For a linked plugin it is the SHA-256 of its ID, product version and interface version together with ``host_build``, the host program's own build identity (its version and commit, or its executable's digest), since the plugin's code is part of the host. Lowercase hexadecimal. .. rust:method:: pub fn validate(&self) -> Result<(), Problem> Checks the plugin's metadata without running any of its hooks. .. rubric:: Trait Implementations .. rust:impl:: impl fmt::Debug for Plugin :noindex: :for: Plugin :trait: fmt::Debug .. rust:method:: fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result :noindex: .. rust:struct:: pub struct Registry The plugins an application offers, checked when it is made: every plugin is valid (its commands included) and has its own ID. Running nothing, it never executes a plugin's hooks. .. rubric:: Implementations .. rust:impl:: impl Registry :noindex: :for: Registry .. rust:method:: pub fn new(plugins: Vec) -> Result Makes a registry of ``plugins``; fails on the first invalid or repeated one. .. rust:method:: pub fn find(&self, id: &str) -> Option<&Plugin> The plugin with exactly the ID ``id``. .. rust:method:: pub fn plugins(&self) -> &[Plugin] Every plugin, in the order given. .. rust:method:: pub fn commands(&self) -> impl Iterator Every contributed command with the plugin that runs it, in the plugins' order. .. rust:struct:: pub struct PublisherSession One publisher, loaded with its configuration and target. Dropping the session unloads the publisher (and ends its program, for an installed one). One session runs one operation at a time; it is ``Send``, so a caller-owned worker may hold it. .. rubric:: Implementations .. rust:impl:: impl PublisherSession :noindex: :for: PublisherSession .. rust:method:: pub fn load(plugin: &Plugin, options: &LoadOptions) -> Result Starts a fresh publisher value and has it read its configuration and target. Fails for a build plugin or a load problem; a failed load is unloaded before this returns. .. rust:method:: pub fn info(&self) -> &PublisherInfo The publisher's identity and capabilities. .. rust:method:: pub fn options(&self) -> &LoadOptions The options the session was loaded with. .. rust:method:: pub fn source(&self) -> &Source What the configuration says to publish. .. rust:method:: pub fn target(&self) -> &str The target, described for people. .. rust:method:: pub fn plan(&mut self, snapshot: &Snapshot) -> Result Compares ``snapshot`` with the target and returns what publishing it would change. It only reads the target. A plan that calls the target unchanged yet lists changes breaks the contract. .. rust:method:: pub fn publish(&mut self, snapshot: &Snapshot, plan: &Plan) -> Outcome Publishes ``plan``, made by this session from ``snapshot``, after checking the snapshot's files again. A dry-run session never publishes. An outcome that names another generation, or no operation, is ``Unknown``, never success. .. rust:method:: pub fn status(&mut self, operation: &str) -> Outcome Reads the outcome of ``operation`` again (``""`` for the last one), writing nothing. .. rust:method:: pub fn recover(&mut self) -> Outcome Settles an operation interrupted at the target's boundary: reads what the target holds and finishes or reports the operation, never forcing the target back. .. rubric:: Trait Implementations .. rust:impl:: impl std::fmt::Debug for PublisherSession :noindex: :for: PublisherSession :trait: std::fmt::Debug .. rust:method:: fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result :noindex: .. rust:struct:: pub struct Entry One file of a snapshot: its path from the root with ``/`` between folders, its size, and the SHA-256 of its contents. Schema 1 publishes every file as a regular, non-executable file. .. rubric:: Fields .. rust:field:: pub path: String The path from the root. .. rust:field:: pub size: u64 The size in bytes. .. rust:field:: pub digest: [u8; 32] The SHA-256 of the contents. .. rust:struct:: pub struct Snapshot A complete, checked site: its folder, its files in the order of their paths' bytes, their total size, and its digest, which names the generation. Dropping a snapshot that is not borrowed removes its private folder. .. rubric:: Implementations .. rust:impl:: impl Snapshot :noindex: :for: Snapshot .. rust:method:: pub fn root(&self) -> &Path The folder holding the site's files. .. rust:method:: pub fn entries(&self) -> &[Entry] The files, sorted by path bytes. .. rust:method:: pub fn bytes(&self) -> u64 The total size in bytes. .. rust:method:: pub fn digest(&self) -> [u8; 32] The generation's digest. .. rust:method:: pub fn mode(&self) -> SnapshotMode How the snapshot holds its files. .. rust:method:: pub fn verify(&self) -> Result<(), Problem> Reads the folder again and checks it holds exactly these files with these contents. A frozen site that changed is refused before anything is published. .. rubric:: Trait Implementations .. rust:impl:: impl Drop for Snapshot :noindex: :for: Snapshot :trait: Drop .. rust:method:: fn drop(&mut self) :noindex: .. rust:struct:: pub struct SnapshotOptions :attributes: #[non_exhaustive] Bounds and placement of a snapshot. Zero bounds mean the defaults: 100,000 files, files under 100 MiB, and 1 GiB in all. It is ``#[non_exhaustive]``: use :rust:fn:`SnapshotOptions::new ` or ``Default``, then assign. .. rubric:: Fields .. rust:field:: pub mode: SnapshotMode How the snapshot holds its files. .. rust:field:: pub temp_dir: Option ``Copy``: where the private folder is made; ``None``: the system's temporary folder. .. rust:field:: pub max_files: usize The most files. .. rust:field:: pub max_file_bytes: u64 The largest file, in bytes. .. rust:field:: pub max_bytes: u64 The most bytes in all. .. rust:field:: pub no_index: bool Accept a site without ``index.html`` at its root. .. rubric:: Implementations .. rust:impl:: impl SnapshotOptions :noindex: :for: SnapshotOptions .. rust:method:: pub fn new(mode: SnapshotMode) -> SnapshotOptions Default bounds, held as ``mode`` says. .. rust:struct:: pub struct Handshake :attributes: #[non_exhaustive] The first line a plugin program writes: the protocol, the highest minor version of each major version it speaks, the interface version it was built against, what it is, its capabilities (publishers), the snapshot schemas it reads (publishers), its hooks (build plugins), and, optionally, the commands it contributes with the command protocol versions it speaks. .. rubric:: Fields .. rust:field:: pub protocol: String :rust:const:`PROTOCOL_NAME ` or :rust:const:`BUILD_PROTOCOL_NAME `. .. rust:field:: pub versions: Vec The protocol versions spoken. .. rust:field:: pub api: Version The interface version built against. .. rust:field:: pub id: String The plugin's ID. .. rust:field:: pub name: String Its display name. .. rust:field:: pub version: String Its product version. .. rust:field:: pub capabilities: Vec A publisher's optional operations. .. rust:field:: pub snapshot_schemas: Vec The snapshot schemas a publisher reads. .. rust:field:: pub hooks: Vec A build plugin's hooks. .. rust:field:: pub commands: Vec The commands the plugin adds to the host's command line (optional; a host that does not know them ignores them). .. rust:field:: pub command_versions: Vec The command protocol versions it speaks; set when ``commands`` is not empty. .. rubric:: Implementations .. rust:impl:: impl Handshake :noindex: :for: Handshake .. rust:method:: pub fn is_build(&self) -> bool Whether this is a build plugin's handshake. .. rust:struct:: pub struct Version A major and minor version. A minor version adds only optional things to its major version; a major version changes or removes something. .. rubric:: Fields .. rust:field:: pub major: u16 Incompatible changes. .. rust:field:: pub minor: u16 Optional additions. .. rubric:: Implementations .. rust:impl:: impl Version :noindex: :for: Version .. rust:method:: pub const fn new(major: u16, minor: u16) -> Version :const: Makes a version from its two numbers. .. rust:method:: pub fn is_compatible_with(self, host: Version) -> bool Whether code built against ``self`` can serve a host speaking ``host``: the same major version and a minor version the host knows. .. rubric:: Trait Implementations .. rust:impl:: impl std::fmt::Display for Version :noindex: :for: Version :trait: std::fmt::Display .. rust:method:: fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result :noindex: .. rubric:: Enums .. rust:enum:: pub enum SourceFormat The markup of a source document. .. rubric:: Variants .. rust:variant:: Rst reStructuredText. .. rust:variant:: Markdown CommonMark or MyST Markdown. .. rubric:: Implementations .. rust:impl:: impl SourceFormat :noindex: :for: SourceFormat .. rust:method:: pub fn name(self) -> &'static str The protocol name: ``"rst"`` or ``"markdown"``. .. rust:method:: pub fn from_name(name: &str) -> Option The format the protocol calls ``name``. .. rust:enum:: pub enum ChangeKind What publishing a file does to the target. .. rubric:: Variants .. rust:variant:: Added A new file. .. rust:variant:: Changed A file with other contents. .. rust:variant:: Removed A file the generation no longer has. .. rubric:: Implementations .. rust:impl:: impl ChangeKind :noindex: :for: ChangeKind .. rust:method:: pub fn name(self) -> &'static str The protocol's name: ``"added"``, ``"changed"`` or ``"removed"``. .. rust:method:: pub fn from_name(name: &str) -> Option The kind the protocol calls ``name``. .. rust:enum:: pub enum State Where a publication stands. .. rubric:: Variants .. rust:variant:: NotStarted No outcome: the publisher reported nothing. .. rust:variant:: Unchanged The target already holds this generation; nothing was written. .. rust:variant:: Accepted The host accepted the generation; its deployment is not confirmed. .. rust:variant:: Pending The deployment of the generation is under way. .. rust:variant:: Live The generation is confirmed live. .. rust:variant:: Failed Nothing was published, or the deployment failed. .. rust:variant:: Unknown The outcome is not known: inspect it before writing again. .. rubric:: Implementations .. rust:impl:: impl State :noindex: :for: State .. rust:method:: pub fn name(self) -> &'static str The protocol's name, such as ``"live"``. .. rust:method:: pub fn from_name(name: &str) -> Option The state the protocol calls ``name``. .. rust:enum:: pub enum SnapshotMode How a snapshot holds its files. .. rubric:: Variants .. rust:variant:: Copy Copies the folder into a private folder, which dropping the snapshot removes. .. rust:variant:: Borrow Checks the folder where it is; the caller keeps it, unchanged. .. rust:variant:: Adopt Checks a private folder where it is; dropping the snapshot removes it. .. rubric:: Traits .. rust:trait:: pub trait BuildPlugin: Send Build hooks: transformations of source text and complete HTML pages, and generated static files. Every hook has a default meaning "service absent" (text passes through unchanged; no assets); :rust:field:`PluginInfo::hooks ` declares which ones a plugin offers. A plugin value is one session's state: :rust:fn:`BuildPlugin::load ` prepares it, the hooks read it, and dropping the value unloads it (close files or children in ``Drop``). Hooks run one at a time; a plugin needs no synchronization of its own. Linked plugins are trusted code: a panic or a hang in a hook reaches the host. Run an untrusted plugin as a program instead (:rust:fn:`crate::process_plugin `). .. rust:method:: fn info(&self) -> PluginInfo What the plugin is and which hooks it offers. It must not change over the value's life; the SDK reads it once, before load. .. rust:method:: fn load(&mut self, ctx: &mut LoadContext<'_>) -> Result<(), Problem> :provided: Prepares the session: reads configuration through ``ctx`` (which fingerprints what it reads) and keeps what the hooks need in ``self``. The default does nothing. .. rust:method:: fn process_source<'a>(&mut self, input: &SourceInput<'a>) -> Result, Problem> :provided: Returns the complete replacement of a primary source document, before parsing. Borrow ``input.text`` when nothing changes. The default returns it unchanged. .. rust:method:: fn process_html<'a>(&mut self, input: &HtmlInput<'a>) -> Result, Problem> :provided: Returns the complete replacement of a rendered HTML page, before staging. The default returns it unchanged. .. rust:method:: fn collect_assets(&mut self) -> Result, Problem> :provided: Returns generated files, staged under ``_static/plugins/ID/``. Paths are relative and portable; the same loaded settings must give the same files in the same order. The default returns none. .. rust:method:: fn commands(&self) -> Vec :provided: The commands the plugin adds to the host's command line; constant over the value's life. The default adds none. .. rust:method:: fn run_command(&mut self, ctx: &mut CommandContext<'_>, name: &str, args: &[String]) -> Result :provided: Runs the contributed command ``name`` (its words joined by spaces, as :rust:fn:`CommandInfo::name ` gives them) with the arguments after its name, and returns the exit status. Runs on a fresh, unloaded value. The default refuses. .. rubric:: Implementors .. rust:impl:: impl BuildPlugin for Box :noindex: :for: Box :trait: BuildPlugin .. rust:impl:: impl BuildPlugin for Fixture :noindex: :module: gd_plugins::build_session::tests :for: Fixture :trait: BuildPlugin .. rust:impl:: impl BuildPlugin for Linked :noindex: :module: gd_plugins::select::tests :for: Linked :trait: BuildPlugin .. rust:impl:: impl BuildPlugin for Paths :noindex: :module: gd_plugins::check::tests :for: Paths :trait: BuildPlugin .. rust:impl:: impl BuildPlugin for ProcessPlugin :noindex: :module: gd_plugins::process_build :for: ProcessPlugin :trait: BuildPlugin .. rust:trait:: pub trait CommandHost What a host offers a contributed command. ``guidedog`` implements it over its own terminal and engine; the SDK implements it over a program's standard streams when a command runs as an installed program (:rust:fn:`crate::serve_command `). .. rust:method:: fn streams(&mut self) -> (&mut dyn Write, &mut dyn Write) The command's standard output and standard error, together, since a command often writes to both at once. .. rust:method:: fn read_line(&mut self) -> Option Reads one line the person typed, without its line break; ``None`` at the end of the input. .. rust:method:: fn build_project(&mut self, request: &BuildRequest) -> Result<(), Problem> Builds ``request``'s project, as ``guidedog build`` does; the build's report goes to the host's error stream. Fails when the build fails or the host builds nothing. .. rubric:: Implementors .. rust:impl:: impl CommandHost for NoHost :noindex: :module: gd_plugins::process_command::tests :for: NoHost :trait: CommandHost .. rust:impl:: impl CommandHost for StdHost :noindex: :module: gd_plugins::process_command :for: StdHost :trait: CommandHost .. rust:trait:: pub trait Publisher: Send A publisher sends a complete, frozen site to a destination such as GitHub Pages. The value is one session's state: :rust:fn:`Publisher::load ` reads the configuration and names the target, the other methods work on it, and dropping the value unloads it (release locks, children and secrets in ``Drop``). The SDK wrappers in :rust:struct:`crate::PublisherSession ` hold every result to the contract, so a publisher that reports no outcome, or the wrong generation, never passes for success. .. rust:method:: fn info(&self) -> PublisherInfo What the publisher is and its optional operations; constant over its life. .. rust:method:: fn load(&mut self, options: &LoadOptions) -> Result Reads the configuration (``options.config``) and returns what to publish and where. A dry-run session must not take locks or credentials it does not need. .. rust:method:: fn plan(&mut self, snapshot: &Snapshot, plan: &mut Plan) -> Result<(), Problem> Compares ``snapshot`` with the target, reading only, and fills in ``plan``, whose generation is already the snapshot's digest. .. rust:method:: fn publish(&mut self, snapshot: &Snapshot, plan: &Plan) -> Outcome Carries out ``plan``, made by this session from ``snapshot``, which the SDK has checked again, and returns the verified outcome. .. rust:method:: fn status(&mut self, operation: &str) -> Outcome :provided: Reads the outcome of ``operation`` again (``""``: the last one), writing nothing. Called only when :rust:field:`Capabilities::status ` is declared. .. rust:method:: fn recover(&mut self) -> Outcome :provided: Settles an operation interrupted at the target's boundary. Called only when :rust:field:`Capabilities::recover ` is declared. .. rust:method:: fn commands(&self) -> Vec :provided: The commands the publisher adds to the host's command line, such as a guided ``publish`` target; constant over the value's life. The default adds none. .. rust:method:: fn run_command(&mut self, ctx: &mut CommandContext<'_>, name: &str, args: &[String]) -> Result :provided: Runs the contributed command ``name`` (its words joined by spaces) with the arguments after its name, and returns the exit status. Runs on a fresh, unloaded value. The default refuses. .. rubric:: Implementors .. rust:impl:: impl Publisher for Box :noindex: :for: Box :trait: Publisher .. rust:impl:: impl Publisher for Nothing :noindex: :module: gd_plugins::build_session::tests :for: Nothing :trait: Publisher .. rust:impl:: impl Publisher for ProcessPublisher :noindex: :module: gd_plugins::process_publish :for: ProcessPublisher :trait: Publisher .. rust:impl:: impl Publisher for Test :noindex: :module: gd_plugins::session::tests :for: Test :trait: Publisher .. rubric:: Functions .. rust:function:: pub fn load_plugin(registry: &Registry, id: &str, options: &PluginOptions) -> Result Loads the build plugin ``id`` of ``registry`` with ``options``: the one-call path to :rust:fn:`PluginSession::load `. Fails when the registry has no such build plugin. .. rust:function:: pub fn check_plugin(plugin: &Plugin, options: &PluginOptions) -> Result<(), Problem> Exercises a build plugin's declared hooks: two fresh loads, each running every hook twice on representative documents and checking the results repeat, then unloading. It never invokes a publisher. Passing shows interoperability, not safety: a linked plugin runs in this process; check an installed program through :rust:fn:`crate::process_plugin ` for crash isolation. .. rust:function:: pub fn config_dir() -> Result The folder of Guidedog's machine state: ``$GUIDEDOG_CONFIG_DIR``, or a ``guidedog`` folder in the user's configuration folder. Fails when the system names none. .. rust:function:: pub fn inspect_entry(path: &str) -> Result Describes the program at ``path`` as a registry entry: checks that ``path`` is an absolute path to a native program (not a script), takes its SHA-256, and runs it in protocol mode to read its handshake. Running it runs its code: call it only for a program the user chose. .. rust:function:: pub fn machine_path() -> Result The registry's file: :rust:const:`MACHINE_FILE ` in :rust:fn:`config_dir `. .. rust:function:: pub fn read_machine(path: &Path) -> Result Reads the registry at ``path``; a missing file is an empty registry. Fails for a file over 1 MiB, invalid TOML, another schema, or a malformed or repeated entry. .. rust:function:: pub fn register(path: &Path, entry: &MachineEntry) -> Result<(), Problem> Adds ``entry`` to the registry at ``path``, which it creates, with its folder, readable only by the user. Refuses an incomplete entry and an ID registered already. .. rust:function:: pub fn unregister(path: &Path, id: &str) -> Result<(), Problem> Removes the entry ``id`` from the registry at ``path``. It removes nothing else: not the program, a site, nor a stored credential. .. rust:function:: pub fn verify_entry(entry: &MachineEntry) -> Result<(), Problem> Checks that the program ``entry`` names is still the one registered: it exists and has the registered SHA-256. .. rust:function:: pub fn process_plugin(entry: &MachineEntry) -> Result A build plugin that runs the registered program ``entry``, one program a session: load starts it and checks its identity and hooks against the entry, dropping the session ends it. Verify the entry (:rust:fn:`crate::verify_entry `) before offering it. Fails for a publisher's entry or undeclared hook names. .. rust:function:: pub fn build_command(program: &str, request: &BuildRequest) -> Command The ``guidedog build -b BUILDER PROJECT OUTPUT`` that carries out ``request``, with its settings, clock and switches as arguments, and its streams left as the caller sets them. ``program`` names the Guidedog program. Borrows both; starts nothing. .. rust:function:: pub fn build_with_program(program: &str, request: &BuildRequest) -> Result<(), Problem> Builds ``request``'s project by starting ``program`` (a ``guidedog``) with ``build -b BUILDER PROJECT OUTPUT``; its report and output go to standard error, so that a command's standard output stays its result. Fails when ``program`` is empty or cannot start, or the build fails. .. rust:function:: pub fn serve_command(plugin: &Plugin, request: &str) -> u8 Runs the command a host's ``request`` (the argument after :rust:const:`COMMAND_FLAG `) names, with ``plugin``, on the program's standard streams, and returns the exit status. A problem is reported on standard error, as the request asks (text or JSON). A project build asked of the host runs the host program the request names. .. code-block:: rust let args: Vec = std::env::args().skip(1).collect(); if args.len() == 2 && args[0] == gd_plugins::COMMAND_FLAG { std::process::exit(i32::from(gd_plugins::serve_command(&plugin(), &args[1]))); } .. rust:function:: pub fn inspect_program(executable: &str, timeout: Duration) -> Result Runs the program at ``executable`` in protocol mode, reads its handshake, and ends it, waiting at most ``timeout``. Running it runs its code: call it only for a program the user chose. .. rust:function:: pub fn process_publisher(entry: &MachineEntry) -> Result A publisher that runs the registered program ``entry`` in protocol mode, one program a session: load starts it and checks its handshake against the entry, dropping the session ends it. Verify the entry (:rust:fn:`crate::verify_entry `) before offering it. Fails for a build plugin's entry. .. rust:function:: pub fn select_build_plugin(linked: &Registry, id: &str, machine_file: &Path) -> Result Finds the build plugin ``id`` as a build does: in ``linked``, the plugins compiled into this program, and otherwise in the machine registry at ``machine_file``, which is read only then. A registered program is verified against its SHA-256 before it is offered. Fails when neither has the ID, when the ID names a publisher, or when the registry or the program cannot be trusted. .. rust:function:: pub fn serve(mut plugin: P) -> ExitCode The whole ``main`` of a build-plugin program: when started with :rust:const:`PROTOCOL_FLAG `, it serves ``plugin`` over standard input and output until the host unloads it, and returns the program's exit status; when started with :rust:const:`crate::COMMAND_FLAG `, it runs the contributed command the request names (:rust:fn:`crate::serve_command `); otherwise it writes a one-line usage note to standard error and returns 2. Keep protocol output on stdout: log to stderr only. .. code-block:: rust fn main() -> std::process::ExitCode { gd_plugins::serve(Badge) } .. rust:function:: pub fn serve_plugin(plugin: &Plugin) -> ExitCode The whole ``main`` of a plugin crate's program, serving the same :rust:struct:`Plugin ` a custom host links: build hooks as :rust:fn:`serve ` does, a publisher as :rust:fn:`crate::serve_publisher ` does. One implementation, two deployments: .. code-block:: rust // In the plugin crate's src/main.rs; its lib.rs exposes `pub fn plugin() -> Plugin`. fn main() -> std::process::ExitCode { gd_plugins::serve_plugin(&badge::plugin()) } .. rust:function:: pub fn serve_streams(plugin: P, mut input: impl BufRead, output: impl Write) -> u8 Serves ``plugin`` over ``input`` and ``output``: writes the handshake, then answers the host's requests until it unloads the plugin or closes ``input``. Returns the exit status: 0 after unload or a closed input, 1 when the host broke the protocol or output failed, 2 for invalid plugin metadata. .. rust:function:: pub fn serve_publisher(mut publisher: P) -> ExitCode The whole ``main`` of a publisher program: when started with :rust:const:`crate::PROTOCOL_FLAG `, it serves ``publisher`` over standard input and output until the host unloads it; started with :rust:const:`crate::COMMAND_FLAG `, it runs the contributed command the request names; otherwise it writes a one-line usage note to standard error and returns 2. .. rust:function:: pub fn serve_publisher_streams(publisher: P, mut input: impl BufRead, output: impl Write) -> u8 Serves ``publisher`` over ``input`` and ``output``: writes the handshake, then answers requests until the host unloads it or closes ``input``. Returns 0 then, 1 when the host broke the protocol or output failed, and 2 for invalid publisher metadata. The server keeps only the current session, snapshot and plan. .. rust:function:: pub fn load_publisher(registry: &Registry, id: &str, options: &LoadOptions) -> Result Loads the publisher ``id`` of ``registry``: the one-call path to :rust:fn:`PublisherSession::load `. Fails when the registry has no such publisher. .. rust:function:: pub fn digest_hex(digest: &[u8; 32]) -> String A digest in lowercase hexadecimal. .. rust:function:: pub fn snapshot(dir: impl AsRef, options: &SnapshotOptions) -> Result Freezes the site in ``dir``: every regular file below it, checked and digested, held as ``options.mode`` says. Refuses a symbolic link or special file, a name Git or a static host cannot serve, two names that differ only in case, a site over the limits, and one without ``index.html`` (unless ``no_index``). A refusal leaves no private folder behind. .. rust:function:: pub fn select_version(h: &Handshake) -> Option The protocol version a host and the program whose handshake is ``h`` share: the same major version, at the lower minor version; ``None`` when they share none. .. rust:function:: pub fn is_valid_id(id: &str) -> bool Whether ``id`` can name a plugin: 2 to 32 lowercase ASCII letters, digits and hyphens, starting with a letter. .. rubric:: Constants .. rust:const:: pub const MAX_COMMANDS: usize = 32 The most commands one plugin may contribute. .. rust:const:: pub const CONFIG_VARIABLE: &str = "GUIDEDOG_CONFIG_DIR" When set, names the folder of Guidedog's machine state instead of the user's configuration folder, for tests and portable installations. .. rust:const:: pub const MACHINE_FILE: &str = "plugins.toml" The registry's file name in :rust:fn:`config_dir `. .. rust:const:: pub const EXIT_ACCEPTED: i32 = 6 Exit status of a publication the host accepted but has not confirmed live yet. .. rust:const:: pub const EXIT_UNKNOWN: i32 = 7 Exit status of an outcome that is not known; inspect it with ``status`` or ``recover``. .. rust:const:: pub const COMMAND_FLAG: &str = "--guidedog-command" The argument that starts a plugin program to run one contributed command; the next argument is the request, one JSON object. .. rust:const:: pub const COMMAND_PROTOCOL_NAME: &str = "guidedog-command" The command protocol's name in a request. .. rust:const:: pub const COMMAND_PROTOCOL_VERSION: Version = Version { major: 1, minor: 0 } The command protocol's version: a handshake lists the versions it speaks in ``command_versions`` beside its ``commands``. .. rust:const:: pub const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(5 * 60) Bounds a publisher request, including its write and response, when the options leave it zero. .. rust:const:: pub const HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(10) Bounds the wait for a program's handshake. .. rust:const:: pub const MAX_BUILD_PLUGINS: usize = 64 The most build plugins one build may select. .. rust:const:: pub const API_VERSION: Version = Version { major: 1, minor: 1 } The version of the publisher interface (:rust:trait:`Publisher `). .. rust:const:: pub const PLUGIN_API_VERSION: Version = Version { major: 1, minor: 0 } The version of the build-plugin interface (:rust:trait:`BuildPlugin `). .. rust:const:: pub const PROTOCOL_VERSION: Version = Version { major: 1, minor: 0 } The publisher process protocol's version. .. rust:const:: pub const BUILD_PROTOCOL_VERSION: Version = Version { major: 1, minor: 0 } The build-plugin process protocol's version. .. rust:const:: pub const PROTOCOL_FLAG: &str = "--guidedog-protocol" The argument that starts a plugin program in protocol mode. .. rust:const:: pub const PROTOCOL_NAME: &str = "guidedog-publisher" The publisher protocol's name in a handshake. .. rust:const:: pub const BUILD_PROTOCOL_NAME: &str = "guidedog-build-plugin" The build-plugin protocol's name in a handshake. .. rust:const:: pub const SNAPSHOT_SCHEMA: i64 = 1 The version of the snapshot manifest and its digest. .. rust:const:: pub const MAX_REQUEST: usize = 1024 * 1024 The largest request line a publisher program reads (1 MiB). .. rust:const:: pub const MAX_RESPONSE: usize = 64 * 1024 * 1024 The largest response line or handshake a host reads (64 MiB). .. rust:const:: pub const MAX_PLUGIN_TEXT: usize = 8 * 1024 * 1024 The largest source or HTML text a hook receives or returns (8 MiB). .. rust:const:: pub const MAX_PLUGIN_ASSETS: usize = 256 The most generated assets one plugin may return. .. rust:const:: pub const MAX_PLUGIN_ASSET_BYTES: usize = 16 * 1024 * 1024 The most generated asset bytes one plugin may return (16 MiB). .. rust:const:: pub const MAX_PATH: usize = 1024 The longest path a plugin input, dependency or published file may have, in bytes.