Skip to main content

FeatureBuilder

Struct FeatureBuilder 

Source
pub struct FeatureBuilder<'a> { /* private fields */ }
Expand description

The feature builder: the value through which a feature declares what it contributes to a registry. Each method records one declaration in the build’s Roster and attributes it to the feature this builder was created for.

The registry build creates one builder per feature and round. It hands one to the feature’s FlmFeature::register method, in the first registration round, where every method may be called; and one to each of the feature’s Finalizers, in the second round, where the methods that declare, fill or require service slots and the method that registers a finalizer return BuildError::ContributionAfterAssembly. Only in the second round does services return the assembled services.

The methods are grouped by what they declare: the language (element, attach, fallback, scoped_package, override_callable, argument_role, element_type_text); capabilities and tables (capability, collection, collection_member, table, external_table); stages (stage, rewrite_stage, ordering); lowering and output (lowering_rule, presentation_element, backend, native_implication, output, workflow, workflow_fields); peer declarations of entities other features own (peer_backend, peer_element, peer_table, peer_slot, peer_scoped_package, peer_element_value, peer_argument_role); options and services (options, service_slot, contribute, contribute_first, require_service); and build hooks and records (finalizer, late_init, style_def, script_def, digest_input). Several of these methods have a variant that takes the target by name instead of by type, or that adds documentation prose: table_named, external_table_named, options_with_docs, contribute_to, contribute_first_to and require_service_named. Two methods read the builder instead of recording a declaration: feature and services.

Every method that records a declaration returns a Result, so that a feature’s register method can end each call with ?, and so that a method can start reporting a problem without a change to its callers. Most methods always return Ok; the others say under # Errors when they fail. Problems with the declarations themselves are reported when the registry is built.

§Examples

use flm_core::core::registry::{BuildError, CapabilityDef, FeatureBuilder};

fn register(b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
    b.capability(CapabilityDef::new("counting.done").docs("Counting has run."))?;
    assert_eq!(b.feature(), "counting");
    Ok(())
}

Implementations§

Source§

impl<'a> FeatureBuilder<'a>

Source

pub fn feature(&self) -> &FeatureName

The name of the feature this builder records for: every declaration made through this builder is attributed to it.

A feature reads it to compose the names of its own entities, so that the name the feature was registered under is the one that appears in the names of its entities (flm.<feature>.<...>).

Source

pub fn services(&self) -> Option<&'a Services>

The assembled services, or None in the first registration round.

The build assembles the service slots between the two rounds, so only a Finalizer can read them. A feature that needs a service to decide what to declare registers a finalizer and makes those declarations there.

Source

pub fn element(&mut self, def: ElementDef) -> Result<(), BuildError>

Declares an element: an element value, the callable names (commands) that produce it, and the syntax of those commands. See ElementDef for how a declaration is written.

The declaration is attributed to this feature, regardless of the value of def.owner.

§Errors

Never fails. A name that clashes with another feature’s, or another problem with the declaration, is reported when the registry is built.

Source

pub fn peer_element_value(&mut self, def: ElementDef) -> Result<(), BuildError>

Declares one more value of an element type that another feature owns, with the commands that produce it: a peer declaration of the element type, which carries the element declaration that element takes.

The declaration lets this feature add a value of the type without depending on the feature that owns the type. That feature’s lowering rules, stages and aspects serve every value of the type, so the value is meaningful only when that feature is registered. A feature declares the element type when any of its declarations other than a peer element value creates an element of that name: an element declaration (a value of its own, or the type alone with no callable name, SyntaxDef::Synthesized), an element of a scoped package, a fallback, a presentation element, or a field that an argument attaches; the language’s structural elements count too.

When the registry is built, the declaration is resolved against the element types that the other declarations of the registry create.

  • If a feature declares the element type, this declaration is kept, attributed to this feature, exactly as element would keep it.
  • If no feature declares it, the build still succeeds, the declaration is dropped (its commands are then unknown commands, like any command no feature defines), and one Note (UnresolvedPeer) joins the registry’s build diagnostics, one per feature and element type, however many values this feature declared for it. Without this rule, a value that no lowering rule lowers would make every rendering plan of the registry fail.

Every such declaration, resolved or not, is listed on the finished registry (FlmRegistry::peer_element_values). See PeerName for the other kinds of peer declaration.

§Errors

Never fails. An unresolved declaration is reported as a Note when the registry is built, and a kept one is checked then like any element declaration.

Source

pub fn element_type_text( &mut self, name: impl Into<ElementName>, docs: impl Into<String>, ) -> Result<(), BuildError>

Gives the element type name its documentation text: what the nodes of that type mean, whatever their element value.

An element type is the name its element values share, and each value carries a text of its own (ElementSpec::docs); this text is the type’s, written once for all its values, not a copy of one value’s text. It is FLM, written as every documentation text is (ElementDef::docs).

This feature must declare the element type, in the sense that peer_element_value defines: one of its declarations other than a peer element value creates an element of that name. A registry holds at most one text per element type, so of several features that declare one type, one gives its text. The language gives the texts of its structural elements, and a presentation element has the text it is declared with.

The finished registry gives the text by the type’s name, with the feature that gave it (FlmRegistry::element_type_text).

§Errors

Never fails. When the registry is built, a text for an element type this feature does not declare is reported as BuildError::UndeclaredElementTypeText, and a second text for one element type as BuildError::DuplicateElementTypeText.

§Examples
use std::sync::Arc;
use flm_core::core::registry::{BuildError, FeatureBuilder, FeatureInfo, FlmFeature, build_registry};
use flm_core::lang::mint::{ElementDef, SyntaxDef};
use flm_core::model::element::ElementSpec;

struct Notes;
impl FlmFeature for Notes {
    fn info(&self) -> FeatureInfo { FeatureInfo::new("notes", "Notes") }
    fn register(&self, b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
        let note = Arc::new(ElementSpec::new("notes.note"));
        b.element(ElementDef::new("notes", ["note"], SyntaxDef::Macro { args: Vec::new() }, note)
            .docs("Starts a note."))?;
        b.element_type_text("notes.note", "A note, set apart from the text around it.")
    }
}

let registry = build_registry([Arc::new(Notes) as Arc<dyn FlmFeature>])?;
let text = registry.element_type_text("notes.note").expect("given above");
assert_eq!(text.owner, "notes");
Source

pub fn attach<A: ?Sized + Any + Send + Sync>( &mut self, element: impl Into<ElementName>, imp: Arc<A>, ) -> Result<(), BuildError>

Attaches the aspect implementation imp to every element value whose element type is called element, including other features’ elements and the language’s structural elements.

An aspect is a piece of behavior attached to an element when the feature registers it and read back through a trait object (see elements and aspects). This method gives behavior to elements a feature does not own: for example, a cross-referencing feature makes headings referenceable without the headings feature depending on it. Give the aspect as its trait-object type, as in b.attach::<dyn Referenceable>("flm.heading", imp). A concrete type fails to compile, because an aspect is looked up by the trait it is requested as.

§Errors

Never fails. When the registry is built, an element type that no feature declares is reported as BuildError::Undeclared, and an aspect that an element already carries as BuildError::AspectCollision.

Source

pub fn fallback(&mut self, def: FallbackDef) -> Result<(), BuildError>

Declares a fallback: the meaning of a callable name in a parsing mode where nothing else defines it. See FallbackDef. The declaration is attributed to this feature.

§Errors

Never fails; problems are reported when the registry is built.

Source

pub fn scoped_package( &mut self, def: ScopedPackageDef, ) -> Result<(), BuildError>

Declares a scoped package. A scoped package is a set of element declarations that is on no scope stack until something adds it: the declaration of an environment body or an argument that refers to the package by name (BodyDef::scoped, ArgDef::scoped), for instance \item inside a list’s body, or a program that adds it to a parsing state (BuiltLang::scoped_package). See ScopedPackageDef.

The package and each of its elements are attributed to this feature.

§Errors

Never fails; problems are reported when the registry is built.

Source

pub fn override_callable( &mut self, kind: CallableKind, name: impl Into<Name>, ) -> Result<(), BuildError>

Declares that this feature’s definition of the callable name name, of kind kind (macro, environment or special character sequence), explicitly replaces another feature’s definition of it.

Two features that define one callable name in one parsing mode, both ordinarily or, where no feature defines it ordinarily in that mode, both weakly (crate::lang::mint::packages), are otherwise a build error, unless the feature order places the feature registered last explicitly after every other of them (crate::core::registry::order); with this declaration, a feature made to replace another states so. The declaration counts only where this feature’s definition applies: in each mode in which the feature is registered last among those that define the name. Elsewhere it is not consulted.

§Errors

Never fails; the language build decides whether the replacement applies.

Source

pub fn capability(&mut self, def: CapabilityDef) -> Result<(), BuildError>

Declares a capability: a registered dotted name for a state of processing that a stage brings about.

§Errors

Never fails. A name already taken in the namespace that capabilities, tables and collections share is reported when the registry is built.

Source

pub fn argument_role( &mut self, name: impl Into<Name>, docs: impl Into<String>, ) -> Result<(), BuildError>

Declares an argument role called name, described by docs: a registered name for what an argument of a command holds, which this feature and others set on arguments with ArgDef::role.

Write docs for a person who reads the registry’s declarations: one line saying what an argument of this role holds.

§Errors

Never fails. A role that another declaration, of this feature or another, declares too is reported when the registry is built, as BuildError::Duplicate.

§Examples
use std::sync::Arc;
use flm_core::core::registry::{BuildError, FeatureBuilder, FeatureInfo, FlmFeature, build_registry};

struct Glossary;
impl FlmFeature for Glossary {
    fn info(&self) -> FeatureInfo { FeatureInfo::new("glossary", "Glossary") }
    fn register(&self, b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
        b.argument_role("glossary.entry", "The key of a glossary entry.")
    }
}

let registry = build_registry([Arc::new(Glossary) as Arc<dyn FlmFeature>])?;
let role = registry.argument_role_named("glossary.entry").expect("declared above");
assert_eq!(role.owner, "glossary");
Source

pub fn peer_argument_role( &mut self, name: impl Into<Name>, ) -> Result<(), BuildError>

Declares that this feature sets the argument role name, which another feature declares, on arguments of its own declarations, without depending on that feature: a peer declaration (PeerName).

A feature may set a role that another feature declares whenever that feature is part of the registry. Declaring the role as a peer is what lets the registry build when that feature is absent. When the registry is built, the declaration is resolved against the roles every feature declares:

  • if a feature declares the role, the declaration changes nothing;
  • if none does, the build still succeeds, one Note (UnresolvedPeer) joins the registry’s build diagnostics, and the arguments of this feature keep the role, of which the registry holds no description.

A role that no feature declares and that this feature did not declare as a peer is a build error (BuildError::UndeclaredArgumentRole), which catches a misspelled name. Declaring the same name again from the same feature has no effect. Two features may each declare the same name.

§Errors

Never fails; an unresolved declaration is reported as a Note when the registry is built.

Source

pub fn collection(&mut self, def: CollectionDef) -> Result<(), BuildError>

Declares a collection: a name for a set of capabilities that any feature may add to.

§Errors

Never fails. A name already taken in the namespace that capabilities, tables and collections share is reported when the registry is built.

Source

pub fn collection_member( &mut self, collection: impl Into<CapName>, member: impl Into<CapName>, ) -> Result<(), BuildError>

Adds the capability member to the collection collection, which any feature may declare, in any order of registration.

When no feature of the registry declares the collection, the build drops the member without any diagnostic. A feature that adds its check to a collection another feature declares must still be registrable on its own, and reporting the absent collection would refuse ordinary registries.

§Errors

Never fails. A member that is not a declared capability is reported when the registry is built.

Source

pub fn table_type_named(&self, name: &str) -> Option<TableType>

The value type of the table name as the declarations collected so far hold it: the type of a table some feature declared, else the type of a peer table this feature declared (peer_table), else None.

A Finalizer reads every feature’s declarations here, since the second registration round runs after the first round of every feature; a feature’s register sees only the features registered before it.

Source

pub fn table<T: Table>( &mut self, name: TableName<T>, docs: impl Into<String>, ) -> Result<TableHandle<T>, BuildError>

Declares a table holding a value of type T, under the name given by T’s TableName constant. A table is typed data that one stage writes beside the frozen trees and other stages read.

A table’s name is also a capability, the capability of the table having been written. This method therefore declares that capability too, and the name must be free in the namespace that capabilities, tables and collections share.

The returned TableHandle is what a stage declares its writes and reads with, and what reads the table’s value at run time.

§Errors

Never fails. A name clash is reported when the registry is built.

Source

pub fn table_named<T: Table>( &mut self, name: impl Into<CapName>, docs: impl Into<String>, ) -> Result<TableHandle<T>, BuildError>

Declares a table holding a value of type T under a name computed at registration, such as flm.lowered.<backend>.

This method does exactly what table does, for a name that is not known at compile time and so cannot be a TableName constant.

§Errors

Never fails. A name clash is reported when the registry is built.

Source

pub fn table_refining_named<T: Table>( &mut self, name: impl Into<CapName>, parent: impl Into<CapName>, docs: impl Into<String>, ) -> Result<TableHandle<T>, BuildError>

Declares a table holding a value of type T under a name computed at registration, whose capability refines the capability parent: a stage that writes the table provides parent too, as a stage that provides a refining capability does (CapabilityDef::refines).

Otherwise exactly table_named. A processing feature declares the table of its rendered formulas this way, as a refinement of the capability of rendered mathematics.

§Errors

Never fails. A name clash, a parent that no feature declares, or a chain of refinements that leads back to itself is reported when the registry is built.

Source

pub fn external_table<T: Table>( &mut self, name: TableName<T>, docs: impl Into<String>, ) -> Result<TableHandle<T>, BuildError>

Declares an external table holding a value of type T. An external table is a table that no stage of the run writes: the caller installs its value when the run is constructed (Externals).

External tables bring data from outside the run into the plan, for example results carried over from a previous run, or a table the host computes itself. The installation satisfies the table’s capability, and a stage that declares a write of the table is a build error.

§Errors

Never fails. A name clash, or a stage that writes this table, is reported when the registry is built.

Source

pub fn external_table_named<T: Table>( &mut self, name: impl Into<CapName>, docs: impl Into<String>, ) -> Result<TableHandle<T>, BuildError>

Declares an external table holding a value of type T under a name computed at registration; otherwise exactly external_table.

§Errors

Never fails; problems are reported when the registry is built.

Source

pub fn stage(&mut self, stage: Arc<dyn Stage>) -> Result<(), BuildError>

Registers an ordinary stage: one that runs after the trees are frozen and computes data, checks something, or performs input and output.

The builder reads the stage’s decl once, here, and the build and every plan use that declaration; a stage’s declaration is therefore fixed for the life of the registry. Register a rewrite stage with rewrite_stage instead.

§Errors

Never fails. A duplicate stage name, a check stage that declares a write, or a reference to an entity no feature declares is reported when the registry is built.

Source

pub fn rewrite_stage( &mut self, stage: Arc<dyn RewriteStage>, ) -> Result<(), BuildError>

Registers a rewrite stage: a stage that turns one tree into another before the trees are frozen.

The builder reads the stage’s decl once, here. It declares at the same time the table of trees that the rewrite publishes, under the name the declaration gives, with the refinement and the default mark the declaration gives. A rewrite’s output is therefore a table like any other, and no other part of the library needs to know that a rewrite produced it.

§Errors

Never fails; problems are reported when the registry is built.

Source

pub fn ordering(&mut self, def: OrderingDef) -> Result<(), BuildError>

Places ordering edges on a stage, this feature’s or another feature’s, saying which capabilities’ providers the stage must run after or before.

§Errors

Never fails. Edges on a stage that no feature registers, or edges that refer to a capability no feature declares, are reported when the registry is built.

Source

pub fn lowering_rule(&mut self, rule: LoweringRule) -> Result<(), BuildError>

Registers a lowering rule: a named registry entity written for one element, which builds the element’s presentation for one backend.

§Errors

Never fails. A duplicate rule name, an element or a backend that no feature declares, or two rules marked as the default for one element on one backend is reported when the registry is built.

Source

pub fn presentation_element<P: PresPayload>( &mut self, name: impl Into<ElementName>, docs: impl Into<String>, ) -> Result<Arc<ElementSpec>, BuildError>

Registers a presentation element: an element that exists only in the trees a backend writes, with no syntax and no callable name of its own, whose nodes carry a payload of type P. Returns the element value.

The builder creates the element value here and returns it, because there is no source syntax to create it from and the backend’s author needs the value itself to build the nodes that carry it. Attach aspects to it with attach, as to any element.

§Errors

Never fails. A name that is also the name of an element that can appear in a parsed document is reported when the registry is built.

Source

pub fn backend(&mut self, def: BackendDef) -> Result<(), BuildError>

Registers a backend: the registration bundle for one output format, with its native set and its lowering, emit and final stages.

The builder registers the three stages as this feature’s own stages, in the order lowering, emit, final; they are scheduled like any other stage. The backend declaration groups them so that a plan recognizes them as one backend.

§Errors

Never fails. A native element that no feature declares, or a duplicate backend or stage name, is reported when the registry is built; so is a native set that does not satisfy a native-set implication, as BuildError::NativeSetIncomplete.

Source

pub fn native_implication( &mut self, def: NativeImplication, ) -> Result<(), BuildError>

Declares a native-set implication: a requirement on what a backend’s native set must contain, checked against every backend of the registry, this feature’s and every other feature’s, when the registry is built.

§Errors

Never fails. An element that no feature declares is reported when the registry is built as BuildError::Undeclared, and a backend whose native set does not satisfy the implication as BuildError::NativeSetIncomplete.

Source

pub fn peer_backend( &mut self, name: impl Into<BackendName>, docs: impl Into<String>, ) -> Result<(), BuildError>

Declares a peer backend: a peer declaration of a backend called name that this feature expects another feature of the registry to register. With it, this feature’s lowering rules may list the backend in their default mark (DefaultMark::OnBackends) without this feature registering the backend or depending on the feature that does.

The declaration registers nothing and counts for this feature alone. When the registry is built, it is resolved against the declarations of every feature:

  • if a feature registers the backend, this feature’s rules that refer to it take part like any other rule;
  • if none does, the build still succeeds, one Note (UnresolvedPeer) joins the registry’s build diagnostics, and every rule of this feature that refers to the backend is set aside: never selected, and never counted by the check that the backend can write every element.

See PeerName for the full rules, and peer_element and peer_table for the presentation elements such a rule produces and the tables it reads.

Declaring the same name again from the same feature has no effect: the repeat is merged into the first declaration, whose docs are kept. Two features may each declare the same name.

§Errors

Never fails; an unresolved declaration is reported as a Note when the registry is built.

Source

pub fn peer_element<P: PresPayload>( &mut self, name: impl Into<ElementName>, docs: impl Into<String>, ) -> Result<(), BuildError>

Declares a peer element: a peer declaration of a presentation element called name, whose nodes carry a payload of type P, that this feature expects another feature of the registry to register with presentation_element. With it, this feature’s lowering rules may list the element in their produces without this feature depending on the feature that owns the element.

The payload type is the declaration’s signature. When the registry is built, the declaration is resolved against the declarations of every feature:

  • a presentation element registered under this name with payload type P resolves it;
  • a presentation element registered with another payload type, or an element of this name that can appear in a parsed document, is refused as BuildError::PeerElementMismatch;
  • a name that no feature declares leaves the declaration unresolved: every rule of this feature that produces the element is set aside, as peer_backend describes.

Declaring the same name again from the same feature with the same payload type has no effect: the repeat is merged into the first declaration, whose docs are kept. Declaring it again with another payload type is a duplicate, refused when the registry is built as BuildError::Duplicate. Two features may each declare the same name, since a declaration counts for its own feature alone.

§Errors

Never fails. When the registry is built, a repeat with another payload type is reported as BuildError::Duplicate, and a payload mismatch as BuildError::PeerElementMismatch.

Source

pub fn peer_table<R: Table>( &mut self, name: impl Into<CapName>, docs: impl Into<String>, ) -> Result<(), BuildError>

Declares a peer table: a peer declaration of a table called name, holding a value of type R, that this feature expects another feature of the registry to declare. With it, this feature’s lowering rules may read the table, and its stages may write it, without this feature depending on the feature that owns the table.

The value type is the declaration’s signature: the type the reading rule expects, which is the type the owning feature declared the table with. When the registry is built, the declaration is resolved against the declarations of every feature: a table declared under this name holding an R resolves it; a table holding another type is refused as BuildError::PeerTableMismatch; and a name that no feature declares leaves the declaration unresolved.

What an unresolved peer table does to a lowering rule depends on how the rule reads it:

  • a rule that reads it as a hard dependency (LoweringDecl::reads) is set aside, as peer_backend describes, because without the table the rule cannot do its work;
  • a rule that reads it optionally (reads_opt) is selected and runs, and finds the table absent; this lets a rule write what it can in a registry that does not hold the other feature.

In both cases, one Note (UnresolvedPeer) joins the registry’s build diagnostics.

A stage of this feature may also write a peer table: the other feature declares the table, and this feature’s stage writes it (for example, the graphics feature’s publish stage writes the copies of images into an output’s artifact table, which the backend declares). When the peer table is unresolved, every stage of this feature that writes it is set aside and not registered, since it would have nowhere to write and the feature that reads the table is absent; the Note lists those stages. The build also drops the ordering edges placed on such a stage (FeatureBuilder::ordering).

A peer table is not an external table: an external table is a table that no stage of the run writes, whose value the caller installs when the run is constructed, and the feature that declares it registers it with external_table; a peer table belongs to another feature, whose stage computes it like any other table.

Declaring the same name again from the same feature with the same value type has no effect: the repeat is merged into the first declaration, whose docs are kept. Declaring it again with another value type is a duplicate, refused when the registry is built as BuildError::Duplicate. Two features may each declare the same name.

§Errors

Never fails. When the registry is built, a repeat with another value type is reported as BuildError::Duplicate, and a value-type mismatch as BuildError::PeerTableMismatch.

Source

pub fn peer_table_of( &mut self, name: impl Into<CapName>, value: TableType, docs: impl Into<String>, ) -> Result<(), BuildError>

Declares a peer table whose value type is given as a TableType rather than as a type parameter: exactly peer_table with R the type value stands for.

For a caller that names tables by name and learns their types from the declarations (table_type_named), such as a Finalizer declaring for a feature written in another language.

§Errors

As peer_table.

Source

pub fn presentation_payload_named(&self, name: &str) -> Option<TypeKey>

The payload type of the presentation element name as the collected declarations hold it (presentation_element), or None when no feature registered a presentation element of that name. Like table_type_named, it sees every feature’s declarations from a Finalizer.

Source

pub fn peer_element_of( &mut self, name: impl Into<ElementName>, payload: TypeKey, docs: impl Into<String>, ) -> Result<(), BuildError>

Declares a peer element whose payload type is given as a TypeKey rather than as a type parameter: exactly peer_element with P the type payload stands for. For the same callers as peer_table_of, with presentation_payload_named.

§Errors

As peer_element.

Source

pub fn peer_scoped_package( &mut self, name: impl Into<Name>, docs: impl Into<String>, ) -> Result<(), BuildError>

Declares a peer scoped package: a peer declaration of a scoped package called name that this feature expects another feature of the registry to declare with scoped_package. With it, the environment bodies and arguments that this feature declares may refer to the package (BodyDef::scoped, ArgDef::scoped) without this feature depending on the feature that owns it.

The declaration registers nothing and counts for this feature alone. When the registry is built, it is resolved against the declarations of every feature:

  • if a feature declares the package, the bodies and arguments that refer to it get its definitions, exactly as without the peer declaration;
  • if none does, the build still succeeds, one Note (UnresolvedPeer) joins the registry’s build diagnostics, and each body or argument of this feature that refers to the package gets no definition from it: a command the package would have defined is an unknown command there, as anywhere else.

A scoped package name that no feature declares and that this feature did not declare as a peer remains the build error MintError::UnknownScopedPackage, which catches a misspelled name. See PeerName for the other kinds of peer declaration.

Declaring the same name again from the same feature has no effect: the repeat is merged into the first declaration, whose docs are kept. Two features may each declare the same name.

§Errors

Never fails; an unresolved declaration is reported as a Note when the registry is built.

Source

pub fn output(&mut self, def: OutputDef) -> Result<(), BuildError>

Registers an output: a name a caller asks for to have something produced, such as text or html.

§Errors

Never fails. An output whose table does not hold an artifact set, or whose capability is neither its table’s capability nor a refinement of it, is reported when the registry is built.

Source

pub fn workflow(&mut self, def: WorkflowDef) -> Result<(), BuildError>

Registers a workflow: a named set of demands together with the choices that go with them.

§Errors

Never fails. A workflow that refers to an output, capability, stage, backend, element or lowering rule that no feature declares, a chain of workflows that leads back to itself, or a render option value whose option type no feature declares or cannot be set on a render request is reported when the registry is built.

Source

pub fn workflow_fields(&mut self, def: WorkflowDef) -> Result<(), BuildError>

Registers fields for the workflow called def.name: every field that def declares replaces that field of the workflow a feature registers under that name with workflow, so that the two make one workflow. When no feature registers a workflow of that name, def is the workflow.

A field is declared when it is set: extends given, a list or a map not empty, docs not empty (WorkflowDef::replace_declared_fields). Fields registered for one name by several features are applied in registration order, the later replacing the earlier, and the fields the embedding program registers with RegistryBuilder::workflow_fields are applied after all of them. A feature uses this method to change some fields of a workflow without knowing whether another feature registers a workflow of that name.

§Errors

Never fails; the combined workflow is checked like any other when the registry is built.

Source

pub fn options<T: Options>(&mut self, bind: Bind) -> Result<(), BuildError>

Declares the option type T, whose values are set where its binding bind allows: on the document, on the render request, on either, or nowhere because the value is fixed when the registry is built (see Bind and option types).

§Errors

Never fails. A second declaration of the same option type, or a workflow that sets a value where the binding does not allow it, is reported when the registry is built.

Source

pub fn options_with_docs<T: Options>( &mut self, bind: Bind, docs: impl Into<String>, ) -> Result<(), BuildError>

Declares the option type T with the binding bind and with documentation prose; otherwise exactly options.

§Errors

Never fails; problems are reported when the registry is built.

Source

pub fn service_slot<S: ?Sized + Any + Send + Sync>( &mut self, name: impl Into<Name>, arity: Arity, docs: impl Into<String>, ) -> Result<(), BuildError>

Declares a service slot called name, holding values of type S (usually a trait-object type), and taking as many contributions as arity allows.

A service is a value that can be shared across threads which one feature supplies for another feature, or for the embedding program, to use. By declaring a service slot, a feature states that something it needs is to be supplied from outside the feature, by another feature or by the embedding program.

§Errors

BuildError::ContributionAfterAssembly when called from a Finalizer: the build assembles the service slots between the two registration rounds, and they cannot change afterwards.

Source

pub fn contribute<S: ?Sized + Any + Send + Sync>( &mut self, imp: Arc<S>, ) -> Result<(), BuildError>

Contributes imp to the service slot whose value type is S, after every contribution already made to it.

§Errors

BuildError::ContributionAfterAssembly when called from a Finalizer.

Source

pub fn contribute_to<S: ?Sized + Any + Send + Sync>( &mut self, slot: impl Into<Name>, imp: Arc<S>, ) -> Result<(), BuildError>

Contributes imp to the service slot called slot, after every contribution already made to it.

When no feature declares that service slot, the registry build fails. For a service slot that another feature owns and that may be absent, use peer_slot instead.

§Errors

BuildError::ContributionAfterAssembly when called from a Finalizer.

Source

pub fn contribute_first<S: ?Sized + Any + Send + Sync>( &mut self, imp: Arc<S>, ) -> Result<(), BuildError>

Contributes imp to the service slot whose value type is S, before every contribution appended to it.

Order matters for a service slot that takes several contributions and consults them in turn; with this method a feature places its contribution first. Among the contributions placed first this way, a read for precedence takes those of the feature placed last in the feature order first (Services::services_by_precedence_named).

§Errors

BuildError::ContributionAfterAssembly when called from a Finalizer.

Source

pub fn contribute_first_to<S: ?Sized + Any + Send + Sync>( &mut self, slot: impl Into<Name>, imp: Arc<S>, ) -> Result<(), BuildError>

Contributes imp to the service slot called slot, before every contribution appended to it. Among the contributions placed first this way, a read for precedence takes those of the feature placed last in the feature order first (Services::services_by_precedence_named).

§Errors

BuildError::ContributionAfterAssembly when called from a Finalizer.

Source

pub fn peer_slot<S: ?Sized + Any + Send + Sync>( &mut self, slot: impl Into<Name>, imp: Arc<S>, ) -> Result<(), BuildError>

Makes a peer contribution: contributes imp to the service slot called slot, a service slot that another feature of the registry is expected to declare. A feature uses it to offer a value to a feature that may not be registered. This is the service-slot form of a peer declaration.

contribute_to is the form for a service slot this feature owns, or one it knows is declared: contributing to a service slot that no feature declares is then a registry build error (ServiceError::UndeclaredSlot), which catches a misspelled name. With this method, the service slot belongs to another feature:

  • if a feature declares the service slot, the value fills it exactly as contribute_to would, after every contribution already made, and with its type checked against the service slot’s value type;
  • if no feature declares it, the value is dropped, the build still succeeds, and one Note (UnresolvedPeer) joins the registry’s build diagnostics, one per feature and service slot, however many values this feature offered to that service slot.

The value type S is the declaration’s signature, written as the type the service slot declares: a trait-object type, as in b.peer_slot::<dyn Greeter>(…), when the value is behavior. A value of another type than the service slot declares is refused, as it is through contribute_to.

Every peer contribution, resolved or not, is listed on the finished registry (FlmRegistry::peer_slots), so a misspelled service slot name can be found on any registry that holds the feature.

§Errors

BuildError::ContributionAfterAssembly when called from a Finalizer: the build assembles the service slots between the two registration rounds, and they cannot change afterwards.

Source

pub fn require_service<S: ?Sized + Any + Send + Sync>( &mut self, ) -> Result<(), BuildError>

Declares that this feature cannot work unless the service slot whose value type is S is filled.

A required service slot that is not filled makes the registry build fail, so a missing service is reported once, when the registry is built, instead of as a failure in the middle of processing a document.

§Errors

BuildError::ContributionAfterAssembly when called from a Finalizer.

Source

pub fn require_service_named( &mut self, slot: impl Into<Name>, ) -> Result<(), BuildError>

Declares that this feature cannot work unless the service slot called slot is filled; otherwise exactly require_service.

§Errors

BuildError::ContributionAfterAssembly when called from a Finalizer.

Source

pub fn finalizer( &mut self, finalizer: Arc<dyn Finalizer>, ) -> Result<(), BuildError>

Registers a Finalizer of this feature: a build hook that runs in the build’s second registration round, once the service slots are assembled.

A feature may register several finalizers; they run in the order registered.

§Errors

BuildError::ContributionAfterAssembly when called from a Finalizer: there are exactly two rounds, so a finalizer cannot add a third.

Source

pub fn late_init(&mut self, hook: Arc<dyn LateInit>) -> Result<(), BuildError>

Registers a LateInit hook of this feature: a build hook that runs once the FLM language is built, for example to compile the templates the feature’s configuration holds.

Unlike finalizer, this method may be called in either round.

§Errors

Never fails. A failure of the hook itself makes the build fail in the late-initialization phase.

Source

pub fn style_def(&mut self, def: StyleDef) -> Result<(), BuildError>

Records a style definition in the registry: a stylesheet that a feature’s output depends on, under an identifier.

A lowering rule or an emitter then requires the definition by its identifier where its output needs it; the backend that writes the output resolves the identifier against the definitions recorded here.

§Errors

Never fails.

Source

pub fn script_def(&mut self, def: ScriptDef) -> Result<(), BuildError>

Records a script definition in the registry: the counterpart of style_def for scripts.

§Errors

Never fails.

Source

pub fn digest_input(&mut self, bytes: &[u8]) -> Result<(), BuildError>

Gives bytes as an input of the registry digest, the number that stands for everything about a registry that can change what processing produces.

The build computes the digest from the declarations it can enumerate. A feature’s configuration may hold other data that changes what processing produces (for example, the text of an author-written template), which the build cannot see. The feature gives that data here, so that data cached under the digest is not reused after the configuration changes.

§Errors

Never fails.

Trait Implementations§

Source§

impl Debug for FeatureBuilder<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for FeatureBuilder<'a>

§

impl<'a> !UnwindSafe for FeatureBuilder<'a>

§

impl<'a> Forget for FeatureBuilder<'a>

§

impl<'a> Freeze for FeatureBuilder<'a>
where &'a mut Roster: Freeze, *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze, &'a Services: Freeze,

§

impl<'a> Move for FeatureBuilder<'a>

§

impl<'a> Send for FeatureBuilder<'a>
where RawVecInner: Send, Arc<str>: Send, Arc<dyn FlmArgumentParser>: Send, Arc<dyn FlmBodyParser>: Send, Arc<ElementSpec>: Send, TypeId: Send, &'static str: Send, Arc<dyn Any + Send + Sync>: Send, Arc<dyn Stage>: Send, Arc<dyn RewriteStage>: Send, Arc<dyn Lower>: Send, NodeRef<Owned, BackendName, LoweringSelection, LeafOrInternal>: Send, BoxRaw<(BackendName, LoweringSelection)>: Send, NodeRef<Owned, BackendName, Vec<ElementName>, LeafOrInternal>: Send, BoxRaw<(BackendName, Vec<ElementName>)>: Send, NodeRef<Owned, OptionKey, OptionValue, LeafOrInternal>: Send, BoxRaw<(OptionKey, OptionValue)>: Send, Arc<dyn Finalizer>: Send, Arc<dyn LateInit>: Send, BoxRaw<ArgumentPlace>: Send, BoxRaw<[Vec<FeatureName>]>: Send, &'a Services: Send,

§

impl<'a> Sync for FeatureBuilder<'a>
where RawVecInner: Sync, Arc<str>: Sync, Arc<dyn FlmArgumentParser>: Sync, Arc<dyn FlmBodyParser>: Sync, Arc<ElementSpec>: Sync, TypeId: Sync, Arc<dyn Any + Send + Sync>: Sync, Arc<dyn Stage>: Sync, Arc<dyn RewriteStage>: Sync, Arc<dyn Lower>: Sync, NodeRef<Owned, BackendName, LoweringSelection, LeafOrInternal>: Sync, BoxRaw<(BackendName, LoweringSelection)>: Sync, NodeRef<Owned, BackendName, Vec<ElementName>, LeafOrInternal>: Sync, BoxRaw<(BackendName, Vec<ElementName>)>: Sync, NodeRef<Owned, OptionKey, OptionValue, LeafOrInternal>: Sync, BoxRaw<(OptionKey, OptionValue)>: Sync, Arc<dyn Finalizer>: Sync, Arc<dyn LateInit>: Sync, BoxRaw<ArgumentPlace>: Sync, BoxRaw<[Vec<FeatureName>]>: Sync, NodeRef<Owned, Name, SlotDecl, LeafOrInternal>: Sync, BoxRaw<(Name, SlotDecl)>: Sync, NodeRef<Owned, Name, Vec<Arc<dyn Any + Send + Sync>>, LeafOrInternal>: Sync, BoxRaw<(Name, Vec<Arc<dyn Any + Send + Sync>>)>: Sync, NodeRef<Owned, TypeKey, Vec<Name>, LeafOrInternal>: Sync, BoxRaw<(TypeKey, Vec<Name>)>: Sync,

§

impl<'a> Unpin for FeatureBuilder<'a>
where &'a mut Roster: Unpin, Arc<str>: Unpin, &'a Services: Unpin,

§

impl<'a> UnsafeUnpin for FeatureBuilder<'a>
where &'a mut Roster: UnsafeUnpin, *const ArcInner<str> is !null: UnsafeUnpin, PhantomData<ArcInner<str>>: UnsafeUnpin, &'a Services: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.