Skip to main content

Crate ulo

Crate ulo 

Source
Expand description

The ulo core: keys, bindings, injection points, scopes, executions, modules, lifecycle, errors, and the enhancer traits a transport implements against.

The core has no async runtime. It uses std::future, the BoxFuture alias, a pluggable Timer and a pluggable Spawn, the two together a Runtime; transports and runtime adapters bring the executor, sockets, timers and signals. Every macro expands to calls on the value-level API re-exported here, which integration crates call directly.

The macros name this crate as ::ulo. A crate that depends on it under another name, framework = { package = "ulo", .. } in its manifest, writes extern crate framework as ulo; at its root for any ulo macro to expand.

Re-exports§

pub use app::App;
pub use app::AppBuilder;
pub use app::AppHandle;
pub use app::Connected;
pub use app::Phase;
pub use app::Wired;
pub use scope::AllowedIn;
pub use scope::HookCapable;
pub use scope::Scope;
pub use scope::ScopeKind;
pub use testing::TestApp;

Modules§

app
The application: the graph plus the singleton store, moving through typestates Wired → Connected → Bound → serving → closed (§2, §9.4).
handle
The binding-handle typestate: the state markers Handle’s parameters take and the traits that decide which methods exist in each state (§9.1). Also the marks on Contribute’s last parameter: Plain on the builder contribute returns, Enhancer on the one enhancer returns, which has no qualified.
panic
The process’s panic hook. Rust runs the installed hook for every panic, on the panicking thread, before the unwinding reaches any catch_unwind, so what ulo redacts in a caught panic reaches its reports and never what the hook already printed; the default hook prints the raw message. install_redacting_hook replaces it with one that prints the message redacted. ulo never installs it: the hook is the process’s, and a library replacing it would replace the application’s own.
scope
Scope markers and the bounds the compiler checks against them (§3.3).
secrets
For the authors of configuration loaders and of module settings: the two ways a secret that reaches a module through its configuration is kept out of the reports the graph writes.
testing
Building a module graph with some bindings overridden, without editing the production modules (§11).

Macros§

hooks
Construct::hooks filled by autoref probing: each of the five hooks registers when the concrete type implements its trait and is a no-op otherwise. #[injectable] emits the same probes; this macro offers them to a hand-written Construct impl that wants all five checked.

Structs§

Alias
alias::<T, Q>(): the new key T @ Q, waiting for the existing one in Alias::of.
BoundAddr
One address a server listens on, as Server::bound reports it.
Cancelled
Resolves when the execution is cancelled: at a client disconnect or the deadline for a call, at the deadline for a standalone execution, and at the end of the drain for either.
Closed
execute and Execution::open from Draining on; load carries it in LoadError::Closed from Stopping on (§9.5). Constructed by the core alone.
ConfigureError
One server’s configuration failure: route-table construction, a duplicate route, TLS loading, CORS validation, endpoint parsing, an inherited socket that does not exist, or a backend limit. Display writes the entry as its report does.
ConfigureErrors
Every failure the servers’ prepare calls reported, one entry per failure, collected across every server before any of them binds (transports DESIGN §2.7, X6). StartupError::Configure carries it, as StartupError::Wiring carries WiringErrors.
Contribute
Contributions to the collection U @ Q, read as Many<U, Q> or, by a transport, through Resolver::entries (§3.2, §7).
ControllerHandle
What ModuleDef::controller returns: the controller it registered, whose routes and gateway paths take a runtime prefix.
Dep
The single binding T @ Q, as the shared Arc every holder of the binding holds.
Dependencies
The declared injection points of a binding, a hook closure, a readiness closure or an enhancer closure: what Construct::dependencies and the factory traits fill in, and what the wiring pass resolves. The wiring pass learns what a binding reads from this list alone.
DifferingSetting
One setting two registrations of a module disagree on: its name and each side’s value as ModuleSettings wrote it, None where that side has no such setting.
DrainToken
The proof that a transport opens a terminal execution. Private field, one source: the core hands it to each transport through Server::drain as Draining begins. Clone, an Arc inside, because a transport opens terminal executions from connection tasks spawned long before the drain; cloning creates no second source.
Draining
Resolves as the drain begins (§9.5), a moment before the servers stop accepting, send GOAWAY and close idle keep-alives: the core fires it, then hands each server its drain. No execution opens from then on, so a request arriving in that moment is refused, not served. The same future on an execution and on an AppHandle, resolving at the same moment; it does not resolve during the before-shutdown stage.
DynamicModule
A module built at runtime by a function, for integration crates. Its identity is the owner type plus the configuration value, so these are still distinct Rust-typed identities.
EndStream
The sentinel an error handler returns on the late path to end a stream cleanly, as if it had returned None (transports DESIGN §2.3, X7). Anywhere else it is an ordinary error.
EnhancerSpec
The enhancers one tier declares for one handler: the controller’s, or the method’s. Each is declared by type (resolved from the container with the controller module’s visibility), by value (built once and shared), or by closure, whose parameters are injection points.
Entries
The contributions to one collection, unresolved, in collection order.
Entry
One contribution to a collection, built on Entry::resolve: the shared singleton, the value, or a per-execution build cached in the current execution.
ExecOptions
Options for a new execution. Each setter keeps the others, so they compose in any order.
Execution
One execution, as its holder owns it. Not Clone: anything else takes a handle. Dropping it ends the execution (§3.8): the execution-scoped instances drop, the drain stops waiting for it, and every handle’s get answers LookupError::ExecutionEnded.
ExecutionRef
A cheap-clone handle to an execution: the same methods as Execution except seed and route_to, so an input a guard or a subtask seeded could never be one the wiring pass did not see, and only the holder decides the module.
Expiry
A bound’s end on a Timer’s clock, ready with the Cut that ended it. The wait is asked of the clock when the Expiry is made, for what is left of the bound then, and a bound already passed by then is Expired without a sleep.
Ext
A typed view of per-execution data: the extension T a guard or middleware wrote earlier in this execution through Extensions::insert.
Extensions
The typed per-execution bag a guard or middleware writes and a handler or an execution-scoped service reads as Ext<T>. Written through a shared reference, so every clone of a transport’s Cx writes the same bag.
GuardRejected
A guard’s Ok(false), as the error handlers see it (§7). Unclaimed, the transport renders its forbidden status.
Handle
What provide, value, the factory methods and the contribute builder return: a handle on the binding registered by that call, through which its second keys, qualifier, construction bound, readiness check and closure hooks are written.
HandlerInfo
A mounted handler as an enhancer and a report read it: its transport key, controller, name, route, shape and declared metadata (transports DESIGN §2.5, X3).
HandlerSpec
One handler, as a transport’s attribute declares it to Mount::handler (transports DESIGN §2.5, X3). Named as EnhancerSpec is.
Hooks
The hooks a Construct type registers. Each method compiles only when T implements the matching trait; a hand-written Construct impl calls the ones it implemented, and hooks! probes all five.
Input
input::<T>(): an execution input, waiting for the transport that seeds it in Input::seeded_by (§6.4).
InputReader
One handler’s read of an execution input, as Mounted::handlers_reading reports it: the handler and its transport, which a refusal writes as the path’s first step against its report’s names, as in UsersController::get (Http), then the steps after it.
Inputs
The execution inputs one transport seeds, written by Transport::inputs (transports DESIGN §2.10, X4).
Key
The pair of a type and a qualifier that a binding is stored under: Key::of::<PgPool, Replica>().
KeyName
A key as the errors name it: PgPool, PgPool @ Replica, dyn Plugin (collection).
Keyed
M as the keyed instance Q: itself a module, built by Module::keyed.
Many
Every contribution to T @ Q, in collection order, from every module in the application.
Metadata
The metadata declared on one handler with #[meta(..)], on the method and on its controller impl (transports DESIGN §2.5).
ModuleDef
What Module::register writes into: imports, bindings, contributions, controllers, exports, inputs, module hooks, secrets and typed metadata. Registration is synchronous and free of I/O; nothing is built until connect.
ModuleHook
The handle a module hook returns: its bound is written once, with .timeout(..) or .unbounded(), or left at Default. A wiring error about the bound names the call that wrote it, and a zero .timeout(..) is refused at wire().
ModuleIdentity
Who a module is: its type, plus its configuration value if it has one, plus a qualifier if it is keyed. Two configurations of one type are two modules; the same configuration imported twice is one, its settings equal in both imports.
ModuleName
A module as the errors name it: the type name or its label, the qualifier, and a position for a second configuration of one type, as in DbModule @ Replica or DbModule #2.
ModuleRef
A handle to one module, for runtime lookups limited to what that module sees (§8.5).
ModuleSettings
The settings a module answers from Module::settings: each a name and its value as Debug writes it, in the order written. Two imports compare by that text, so a value whose Debug text differs between equal values, a HashMap iterating in another order or a pointer, makes two equal registrations differ.
Mount
Where a controller declares its handlers. Called during wire(), so the wiring pass knows every handler’s transport, enhancers and parameter reads before anything is built.
Mounted
What a server receives when it prepares and binds: its transport’s handlers and the app.
MountedHandler
A handler as a transport receives it when it prepares and binds: its name, its controller and module, its enhancer tiers, its HandlerInfo and the transport’s own handler value.
Next
The rest of the interceptor chain and the handler, handed to Interceptor::intercept.
PanicRecovered
A panic in the pipeline, caught by dispatch and offered to the error handlers as the call’s error (§7). Unclaimed, the transport renders its internal-error status.
Permanent
Marks a failure that retrying this start, with this configuration on this runtime, cannot mend: bad credentials, an unknown database, a runtime the integration does not support, a migration that failed, a runtime that has shut down (RuntimeShutDown). A process restart brings a new runtime, which is a different start. A readiness attempt whose error is one ends the check at once, with no further attempt and no backoff, as ConnectError::Readiness { reason: Errored(..) }; is_permanent finds one in a StartupError, so main can tell a start that retrying cannot mend from one it might.
PrepareEntry
One failure a PrepareError lists, as data a test or a tool reads without parsing the report’s text: the types it names, the source line that declared what failed, what failed, and the route scopes involved, and, for what was refused as something that would never run, why.
PrepareError
A prepare error whose text names types: what a server answers, boxed, so the startup report decides how each name prints. The report runs TypeName::colliding over the names of every server’s PrepareError and every failing transport, and calls text with the result, so a type that prints alike with a different type another server names, or with a transport, is written with its full path.
PreparePanicked
A server’s prepare that panicked, caught by listen() and reported as that server’s ConfigureError, whose source holds it. The other servers’ prepare still run, and nothing binds. is_panic recognises it.
Redacted
An error from outside the core, after the redaction function. Formatting writes the redacted text and never the original; source() is None, so a reporter walking the chain stops at the text too. The original is reached through downcast_ref and into_inner alone, which is what lets an error handler map a constructor’s domain error to a status.
Refused
What a runtime that has shut down answers Timer::try_sleep and Spawn::try_spawn with.
Requirement
What one injection point reads, written by FromContainer::describe and checked by the wiring pass against the visibility of the module the injection point belongs to.
Resolver
The view an injection point reads through: the graph, the module whose visibility applies, and the current execution when there is one.
RuntimeMissing
listen()’s refusal of an app that binds a transport with no Runtime (§9.5), stored in StartupError::Bind’s source like a transport’s error; source.downcast_ref::<RuntimeMissing>() tells it from a port already taken.
RuntimeShutDown
Work that ended because the runtime refused a wait, having shut down: a loop whose pacing wait was refused, or a bounded wait whose bound was. Reported where a reader learns why the work ended, in place of an elapsed bound or a loop out of attempts, neither of which happened. The core reports a hook, a construction, a readiness check, the shutdown cap or a transport’s close bound the runtime refused as FailureReason::Errored holding one. Retrying this start on a runtime that has shut down cannot succeed, so whoever raises one in a startup error raises it inside Permanent.
Secret
A value the redaction function replaces wherever it appears in an error this graph reports, once registered: by m.secret(&self.url), by #[module] for every Secret<_> field of a configured module, or by binding it with m.value(..).
Shutdown
The outcome of a shutdown, received by serve and by every close caller (§9.5).
ShutdownError
One outcome, several receivers; the failures sit behind the Arc.
Signal
The name of what started a shutdown: an OS signal ("SIGTERM") or a reason a job gives close ("done").
TaskHandle
A spawned task: abort to stop it, .await for how it ended, drop to let it run on.
TraceContext
A trace context: a trace ID, a span ID, the flags as bits and the trace state.
TraceState
A tracestate list: key=value members, at most 32, each key once, in order (§3.3). Display writes the header value, members joined by ,.
TypeName
A type as an error report names it: TypeName::of::<my_app::User>() prints User, and with {:#} prints my_app::User.
UndeclaredRead
A hand-written Construct read a key its dependencies does not declare.
ValueHandle
A spawned task that answers a value, as spawn_with starts it: Ok with the value, or Err with TaskEnd::Aborted or TaskEnd::Panicked. Polling after the value was taken answers Err(TaskEnd::Finished).
WiringErrors
Every failure wire() found, one entry each, in the order the six steps of §10.1 found them. Display writes the full report:

Enums§

BindingKind
Whether a key holds one binding or a collection of contributions.
Bound
How long a hook, a construction or a readiness check may take.
BoundItem
The item a bound is written on, as WiringError::ZeroBound names it.
CancelReason
Why an execution was cancelled (transports DESIGN §2.6, X5). Written once, beside the cancellation signal: the first cancel_with decides it, and a cancelled execution always has one.
ConnectError
A failure in the connect phase, on StartupError::Connect from connect and on LoadError::Connect from load.
ConstructError
Why a constructor did not return its instance.
Cut
What ended a timeout or an Expiry before its work: the bound passing on the clock, or the clock’s runtime refusing to time it, having shut down.
DispatchStage
Which stage of dispatch panicked.
FailureReason
Why a hook, a construction, a readiness check or a transport’s close did not complete. One enum for every place one can fail, so a timeout reads the same on an init hook, a destroy hook, a constructor, a check and a close.
HookKind
Which hook a ConnectError::Hook or ShutdownFailure::Hook names.
InputOrigin
One source of an execution input’s key, as WiringError::InputConflict names it. at is the call that declared or bound it.
LateOutcome
What dispatch_late tells the transport to do with an error raised after its reply began streaming (transports DESIGN §2.3, X7). An Err item cannot change a status, so every outcome is rendered in the transport’s mid-stream form.
Limit
Which limit a TimedOut hit.
LoadError
Why load did not return a ModuleRef (§8.6).
LoadRefusal
What a lazily loaded module may not bring, because the graph has been handed out (§8.6).
LookupError
LookupKind
What a LookupError::NotFound did not find.
MetaTier
Which tier declared a metadata value.
ModuleSite
Where a module was registered, as WiringError::DifferingSettings names each side.
ServeEnd
How a transport’s serve ended while the app was still running, on ShutdownFailure::Serve.
Shape
The call shape a handler’s signature declares: a streamed request comes from an inbound-stream parameter, a streamed reply from a stream return (transports DESIGN §5.1, §6.1).
ShutdownFailure
StartupError
StreamOutcome
How a reply stream ended, as Execution::on_stream_end callbacks receive it.
TaskEnd
How a spawned task ended, as its handle answers it. Cloning shares a panic’s message.
TraceMode
Whether the app reads and writes W3C trace headers, set with AppBuilder::trace.
TraceOrigin
Where an execution’s context came from, which decides how a client writes it out (§6.3).
Unreached
Why prepare refused something it was given as something that would never run, as PrepareEntry::reason reads it. Display writes the clause the refusal’s text ends with, so the text follows from the reason.
WiringError
One wiring failure. at is the source location of the registration call that declared the offending item, captured with #[track_caller].

Constants§

RUNTIME_SHUT_DOWN
The reason a failure the runtime’s refusal caused is reported under: by RuntimeShutDown, and by a transport that answers it as a wire reason, as an RPC call’s ErrorInfo does.

Traits§

BeforeApplicationShutdown
Construct
A type the container builds, with its dependencies read from its injection points.
Controller
The mark of a dispatch target: a Construct type a transport reaches through the handlers its Handlers impl declares, one per transport route, message pattern, gRPC method or WebSocket event. The trait has no methods; what a controller mounts is Handlers::mount, and Handlers: Controller.
ErasedErrorHandler
The dyn-compatible twin of ErrorHandler; its trait object is the role key AnyErrorHandler.
ErasedGuard
The dyn-compatible twin of Guard, implemented for every guard; its trait object is the role key AnyGuard.
ErasedInterceptor
The dyn-compatible twin of Interceptor; its trait object is the role key AnyInterceptor.
ErrorHandler
Errors reach the error handlers method level first, then controller, then global. Ok claims the error with a reply; Err hands the next handler the error it returns, the same one or a reshaped one. A guard’s refusal arrives as GuardRejected, and a panic in a guard, an interceptor, the handler or an earlier error handler as PanicRecovered.
Factory
A closure whose parameters are injection points and which returns a future: |cfg: Dep<DbConfig>| async move { .. }. Implemented for closures of zero to twelve parameters.
FromContainer
How every injection point is read. Its type decides what it reads: the container reads T @ Q for Dep<T, Q>, whichever identifier or alias the user wrote.
Guard
Decides whether a call proceeds. Ok(true) admits it. Ok(false) refuses a caller the guard knows and will not admit, as GuardRejected: 403 on HTTP, PERMISSION_DENIED on gRPC. Err(CallError::unauthorized(..)) refuses a caller that has not authenticated: 401 with its challenge on HTTP, UNAUTHENTICATED on gRPC. Any other Err goes to the error handlers as it stands. See ulo_transport::CallError::unauthorized for an example.
Handlers
The handlers of a controller, which ModuleDef::controller and #[module]’s controllers mount: a type registered there implements it, and through it Controller. #[handlers] writes the impl, whose mount declares each handler of the impl block. A controller that mounts its handlers by hand, a WebSocket gateway implementing Gateway among them, implements it itself, <Self as Gateway>::mount(m) for a gateway.
Interceptor
Meta
Typed per-module metadata that a transport reads, written through ModuleDef::meta. ulo-http stores its route middleware this way.
Module
A module: an identity and a synchronous, I/O-free registration.
OnApplicationBootstrap
OnApplicationShutdown
OnModuleDestroy
OnModuleInit
Role
The role keys: AnyGuard<T>, AnyInterceptor<T> and AnyErrorHandler<T> for every T: Transport, and nothing else.
Runtime
The app’s clock and executor in one value, set with AppBuilder::runtime. Services read it as Dep<dyn Runtime>, and Dep<dyn Timer> resolves to the same object; after a later AppBuilder::timer, Dep<dyn Runtime> spawns on the runtime and times with that timer. Either way the object is the app’s wrapper around the runtime given, which redacts a spawned task’s panic with the app’s secrets. Implemented for anything that implements both halves.
RuntimeTask
A runtime’s own handle to one task, boxed inside a TaskHandle. A runtime adapter implements it; code that spawns never sees it.
Server
Implemented by a transport’s server: handed to app.bind(..), prepared and bound by listen(), driven by serve, drained and closed by the shutdown sequence (§9.4, §9.5).
ShutdownFactory
A closure before_shutdown or on_shutdown takes on a binding handle or a ModuleDef: the shutdown’s Signal first, then any number of injection points, returning a future of ().
Spawn
Starts tasks on a runtime’s executor. With Timer it makes a Runtime.
Timer
The app’s one clock. Every wait the core times, the drain, a hook, a construction, a readiness check, runs through it; it is set on the builder and supplied by a runtime adapter.
TraceSource
The parent of an execution’s spans, as a tracer sees it: the hook a transport’s span calls between creating the span and first entering it (integrations §6.4, I7).
Transport
Implemented by marker types in transport crates: ulo_http::Http, ulo_rpc::Rpc, …
TransportMetadata
A metadata type that means something on one transport alone, naming it (transports DESIGN §2.5, X24): ulo_http::Timeout and ulo_http::MaxBody name Http.

Functions§

dispatch
Runs handler’s enhancer stack around call for one call. exec is the call’s execution, the one cx wraps; call receives a clone of cx and answers the handler’s reply.
dispatch_late
Runs handler’s error handlers over err, an error that arrived after the reply started: an Err item of a reply stream, the first included, since dispatch returns a streaming reply without pulling it (transports DESIGN §2.3, X7).
is_panic
Whether error holds a panic the core caught, whichever shape it arrived in. Inside a call there are two: PanicRecovered from a guard, an interceptor, the handler or an error handler, and LookupError::Construct with reason: Panicked from a build the container ran for the call, an enhancer, the controller or one of their dependencies. An error handler that answers every panic alike tests this instead of matching both.
is_permanent
Whether retrying this start, with this configuration on this runtime, cannot succeed: the failure carries a Permanent, or it is a misconfiguration by its phase. A process restart brings a new runtime, which is a different start.
recover
Offers err to the error handlers where no dispatch ran around it: an error or a panic in a transport’s pre-dispatch stage (transports DESIGN §3.3). With Some(handler), a route matched: handler’s method tier, then its controller tier, then the global tier. With None, nothing matched, and only the global error handlers of T apply.
spawn_with
Spawns fut on runtime and answers a handle that resolves to its value. The value is left in a slot the handle reads once the task has ended, so no channel is involved; abort and drop mean what they mean on TaskHandle. Polling after the value was taken answers Err(TaskEnd::Finished).
timeout
fut raced against an Expiry of d: Err with the Cut when the bound ends first, dropping fut at its current await. fut is polled first, so work that completes in the poll the bound passes in counts as done, and the ties with a refusal are the Expiry’s.
timeout_at
timeout for a bound ending at until on timer’s clock.

Type Aliases§

AnyErrorHandler
AnyGuard
The role key for global guards: m.enhancer::<AnyGuard<Http>>().provide::<AuthGuard>(|a| a).
AnyInterceptor
BoxError
BoxFuture

Attribute Macros§

construct
Marks the constructor inside an #[injectable] or #[controller] impl when it is not named new; the attribute on the impl reads and removes it. Anywhere else it is an error.
controller
A controller: a type the container builds and its transports reach, through the handlers of its #[handlers] impl. Only another controller injects one; wire() refuses a read of a controller by any other binding.
error_handlers
Error handlers, with the same forms as #[guards].
guards
Guards for every handler of a #[handlers] impl, or for one method: by type (AuthGuard), transport-scoped by type (http = AuthGuard), by value (value = expr), or by closure (with = |u: Ext<CurrentUser>| ..). Read and removed by #[handlers], so on the impl it goes below #[handlers]; on a method it may sit inside cfg_attr; anywhere else it is an error.
handlers
A controller’s handler impl, on every transport: writes impl ulo::Handlers, whose mount registers each handler, with the impl’s #[guards], #[interceptors], #[error_handlers] and #[meta] as the controller tier and each method’s as the method tier; every other item stays as written. A handler is a method carrying its transport’s attribute, #[ulo_http::get(..)], #[ulo_rpc::message(..)], #[ulo_ws::message(..)] or #[ulo_grpc::method]. The controller itself is declared with #[controller], on the struct or stacked on this impl in either order, where new or the #[construct] fn builds it, and a module that registers the controller mounts these handlers through Handlers::mount. Handlers requires Controller, so on a type that is not a controller, one declared #[injectable] among them, #[handlers] is a compile error naming Controller.
injectable
A type the container builds and injects into others: a provider, listed under a module’s providers.
interceptors
Interceptors, with the same forms as #[guards].
meta
Declared metadata on a handler or on its #[handlers] impl: plain Send + Sync + 'static values, built once when the handler mounts, which guards and interceptors read through cx.exec().handler(). The method’s declaration of a type wins over the impl’s. Read and removed by #[handlers], so on the impl it goes below #[handlers]; on a method it may sit inside cfg_attr; anywhere else it is an error.
module
A module: imports, providers, controllers, exports and global, lowered to a Module impl whose register calls the value API. A struct with fields is a configured module, identified by value, and every Secret<_> field is registered for redaction.