Skip to main content

Registry

Struct Registry 

Source
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

Source

pub fn new(exprs: ExprEngine) -> Self

A registry holding the eight built-ins, compiling against exprs.

Source

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 Reference whose field is 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_fields on a config that is not Templated, which would never compile them;
  • a Templated config with no runtime_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 Templated cannot compile;
  • runtime_fields holding several outputs without exactly one marked primary, which #[derive(FunctionConfig)] refuses at expansion: no output, or a guess, would be the one Ctx::emit_default writes through;
  • a field’s declared default that its kind cannot compile, which would otherwise surface as the author’s INPUT_PARSE in every compile that leaves the key out.
Source

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.

Source

pub fn layer<L: CallLayer>(&mut self, layer: L)

Adds a layer around every host call. The first registered is the outermost.

Source

pub fn exprs(&self) -> &ExprEngine

The engine expressions compile against.

Source

pub fn catalogue(&self) -> impl Iterator<Item = FunctionInfo<'_>>

Every function: the eight built-ins in BUILTIN_FUNCTIONS order, then the host functions by name.

Source§

impl Registry

Source

pub fn compiler(&self, options: CompileOptions) -> Compiler

A compiler for this registry’s functions, with options.

Trait Implementations§

Source§

impl Clone for Registry

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Registry

Source§

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

The function names, in catalogue order.

Source§

impl Default for Registry

Source§

fn default() -> Self

The eight built-ins, compiling against ExprEngine::default.

Auto Trait Implementations§

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.