Rust

hook

Module

Hooks and routes: callbacks with declared params and injections, and the resources they are injected from.

Contents

use utopia_http::Hook;
Rust
pub struct Hook

A callback with its declared params, injections, groups and labels.

use utopia_http::Param;
Rust
pub struct Param

A param a hook or route declares: its default, validator and metadata.

use utopia_http::Resources;
Rust
pub struct Resources

A container of resources by name, falling back to a parent container.

The application's static resources are the parent of every request's context.

Also implements Debug.
use utopia_http::Route;
Rust
pub struct Route

A route: a hook bound to HTTP methods and a path.

A route dereferences to its Hook, so the hook's setters and getters apply to it directly.

Also implements Deref, DerefMut.
use utopia_http::Scope;
Rust
pub struct Scope<'a>

What a callback receives: its params and injections, the request being dispatched and its response.

use utopia_http::Check;
Rust
pub enum Check

A param's validator: an instance, or a factory called with its injections.

Also implements From.
use utopia_http::ParamDefault;
Rust
pub enum Default

A param's default: a value, or a factory called with its injections.

Re-exported from the crate root as ParamDefault.

Also implements From.
use utopia_http::action;
Rust
pub fn action<F>(f: F) -> Action where F: for<'a> Fn(Scope<'a>) -> BoxFuture<'a, Result<()>> + Send + Sync + 'static,

Wraps an async callback into an Action.

Rust
pub type Action = Arc<dyn for<'a> Fn(Scope<'a>) -> BoxFuture<'a, Result<()>> + Send + Sync>

A hook or route callback: takes the Scope of a call and returns a future.

Rust
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>

A boxed, sendable future, as hook and route callbacks return.

Rust
pub type DefaultFactory = Arc<dyn Fn(&[Resource]) -> Value + Send + Sync>

Builds a param's default from its injections.

Rust
pub type Resource = Arc<dyn Any + Send + Sync>

An injectable resource: any shared value, read back by type with Scope::resource.

Rust
pub type ValidatorFactory = Arc<dyn Fn(&[Resource]) -> Arc<dyn Validator> + Send + Sync>

Builds a param's validator from its injections.