pub struct Registry { /* private fields */ }Expand description
Functions and layers, plus the ExprEngine they compile against.
Arc inside: a clone is cheap and shares everything. Registering on a
clone copies the table once and leaves the original as it was, which is
how a host reroutes a name for some programs and not others.
use dataflow_rs::{Ctx, Function, Outcome, Registry, Result};
struct Ping;
impl Function for Ping {
type Config = ();
async fn call(&self, _ctx: &mut Ctx<'_>, _cfg: &()) -> Result<Outcome> {
Ok(Outcome::Ok)
}
}
let mut registry = Registry::default();
registry.register("ping", Ping);
let names: Vec<&str> = registry.catalogue().map(|f| f.name).collect();
assert_eq!(names[..2], ["map", "validation"]);
assert_eq!(names.last(), Some(&"ping"));Implementations§
Source§impl Registry
impl Registry
Sourcepub fn new(exprs: ExprEngine) -> Self
pub fn new(exprs: ExprEngine) -> Self
A registry holding the eight built-ins, compiling against exprs.
Sourcepub fn register<F: Function>(&mut self, name: &str, f: F)
pub fn register<F: Function>(&mut self, name: &str, f: F)
Registers f under name, asking it for its spec
once. A name registered before is replaced.
§Panics
On a reserved name: one in
BUILTIN_FUNCTIONS, since a built-in
cannot be shadowed, or validate, v3’s alias for validation, which
the compat reader rewrites before any name is looked up. A host that
registers names from data checks them with
def::is_reserved_function first.
On a spec the function’s config cannot honour, a host bug best found once, here:
- a
Referencewhosefieldis not an authored path, or does not reach a field of the config: it starts at one of the config’s fields, and each segment below is a field of a nested config, an index into a list or a key of a map; nothing goes below a scalar, an expression or an output, and anything may go below a literal of any JSON, an object or an array, a document, or a runtime-declared set of fields; runtime_fieldson a config that is notTemplated, which would never compile them;- a
Templatedconfig with noruntime_fields, which has nothing to compile; - two config fields with the same name, which would make lookup and resolution disagree;
- a runtime field with a nested, list, map or templated kind, which
Templatedcannot compile; runtime_fieldsholding several outputs without exactly one markedprimary, which#[derive(FunctionConfig)]refuses at expansion: no output, or a guess, would be the oneCtx::emit_defaultwrites through;- a field’s declared
defaultthat itskindcannot compile, which would otherwise surface as the author’sINPUT_PARSEin every compile that leaves the key out.
Sourcepub fn try_register<F: Function>(
&mut self,
name: &str,
f: F,
) -> Result<(), Error>
pub fn try_register<F: Function>( &mut self, name: &str, f: F, ) -> Result<(), Error>
register, refusing instead of panicking: a name
taken from data, or a Function implementation built at run time,
need not be a host bug.
§Errors
ErrorKind::Config for everything register panics on: a reserved
name, or a spec its config cannot honour.
Sourcepub fn layer<L: CallLayer>(&mut self, layer: L)
pub fn layer<L: CallLayer>(&mut self, layer: L)
Adds a layer around every host call. The first registered is the outermost.
Sourcepub fn exprs(&self) -> &ExprEngine
pub fn exprs(&self) -> &ExprEngine
The engine expressions compile against.
Sourcepub fn catalogue(&self) -> impl Iterator<Item = FunctionInfo<'_>>
pub fn catalogue(&self) -> impl Iterator<Item = FunctionInfo<'_>>
Every function: the eight built-ins in
BUILTIN_FUNCTIONS order,
then the host functions by name.