hook
ModuleHooks: callbacks with the params, injections, groups and labels they declare.
Contents
use utopia_servers::Arguments;pub struct ArgumentsWhat a callback receives: its arguments by name, in the order the server resolved them.
use std::sync::Arc;
use serde_json::json;
use utopia_servers::{Argument, Arguments};
let mut args = Arguments::new();
args.push("email", Argument::Value(json!("me@example.com")));
args.push("db", Argument::Resource(Arc::new(String::from("primary"))));
assert_eq!(args.value("email"), Some(&json!("me@example.com")));
assert_eq!(args.resource::<String>("db").map(String::as_str), Some("primary"));use utopia_servers::Hook;pub struct HookA callback with its description, params, injections, groups and labels.
use serde_json::json;
use utopia_servers::{Hook, Param};
use utopia_validators::Text;
let mut hook = Hook::new();
hook.inject("user").param("x", Param::new(json!(""), Text::new(10), "")).inject("time");
assert_eq!(hook.dependencies(), ["user", "time"]);
assert_eq!(hook.injections()["time"].order, 2);Default, Debug.use utopia_servers::Injection;pub struct InjectionA resource a hook injects, and its position among the hook's params and injections.
use utopia_servers::Param;pub struct ParamA param a hook declares: where its value comes from, how it is validated, and what documents it.
use serde_json::json;
use utopia_servers::Param;
use utopia_validators::Text;
let param = Param::new(json!(""), Text::new(64), "Project ID.")
.optional(true)
.aliases(&["project", "project_id"]);
assert!(param.optional);
assert_eq!(param.aliases, ["project", "project_id"]);use utopia_servers::Argument;pub enum ArgumentOne resolved argument of a callback.
Debug.use utopia_servers::Check;pub enum CheckA param's validator: an instance, or a factory called with its injections.
From, Debug.use utopia_servers::ParamDefault;pub enum DefaultA param's default: a value, or a factory called with its injections.
Re-exported from the crate root as ParamDefault.
From, Debug.pub type Action = Arc<dyn Fn(Arguments) -> BoxFuture<'static, Result<(), Error>> + Send + Sync>A hook's callback: receives its resolved Arguments.
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>A boxed, sendable future, as hook callbacks return.
pub type DefaultFactory = Arc<dyn Fn(&[Resource]) -> Value + Send + Sync>Builds a param's default from its injections.
pub type Resource = Arc<dyn Any + Send + Sync>An injectable resource: any shared value.
pub type ValidatorFactory = Arc<dyn Fn(&[Resource]) -> Arc<dyn Validator> + Send + Sync>Builds a param's validator from its injections.