std/context
Import with import std/context.
Exports
Section titled “Exports”Types
type Context
Section titled “type Context”type Context
Per-life execution context, threaded by the runtime through every
call stack. Programs store it on their concrete app struct and read it as
MyApp.context; an ordinary block with
with MyApp.context = Context.with_X(MyApp.context, ...) derives a
child context for that block’s remaining statements.
Opaque: user code cannot construct a Context value directly.
Only Context.root() (for boot construction), the language
runtime, and the Context.with_* derivers produce them.
Context.root
Section titled “Context.root”fn root(): Context
type function on Context
Construct a fresh root Context — no deadline, not canceled, no parent. Intended for use while constructing the program’s app value.
Context.canceled?
Section titled “Context.canceled?”fn canceled?(c: Context): Bool
type function on Context
Has the current context been canceled (deadline expired or runtime cancellation triggered)?
Context.deadline
Section titled “Context.deadline”fn deadline(c: Context): Maybe<Instant>
type function on Context
Absolute deadline of this context, if any.
Context.deadline_remaining
Section titled “Context.deadline_remaining”fn deadline_remaining(c: Context): Maybe<Duration>
type function on Context
Time until deadline, if any. None if no deadline; Some(0) if the deadline has passed (canceled).
Context.with_deadline
Section titled “Context.with_deadline”fn with_deadline(c: Context, at: Instant): Context
type function on Context
Child context with deadline at at. If the parent has a tighter
deadline already, the parent’s deadline wins (no-op).
Context.with_timeout
Section titled “Context.with_timeout”fn with_timeout(c: Context, dur: Duration): Context
type function on Context
Child context with deadline at now() + dur. If the parent has
a tighter deadline already, the parent’s deadline wins.
Context.with_value
Section titled “Context.with_value”fn with_value<'T>(c: Context, value: 'T): Context
type function on Context
Return a child context with value stored under its Nomi type.
Context values are intended for request- or execution-scoped metadata
such as trace IDs, auth subjects, or locale. Prefer explicit app
fields (MyApp.store, MyApp.logger) for dependencies, and prefer
domain types (TraceId, Subject) over raw scalars.
Context.value
Section titled “Context.value”fn value<'T>(c: Context, value_type: Type<'T>): Maybe<'T>
type function on Context
Look up the nearest value of type T, walking through parent
contexts when this context has not overridden that type.
Context.value(context, TraceId)
Context.inspect
Section titled “Context.inspect”impl Debug
fn inspect(value: Context): String
impl Debug.inspect