Crate ctx [] [src]

Ctx defines the Context type, which carries deadlines, cancelation futures, and other request-scoped values across API boundaries and between processes.

It is similar to Go's context package. The main use case is to have incoming requests to a server create a Context. This Context is propagated in the chain of function calls between the incoming request until the outging response. On its way, the Context can be replaced with a derived Context using with_cancel, with_deadline, with_timeout, or with_value.

Structs

Context
WithCancel
WithDeadline
WithValue

Enums

ContextError

Traits

InnerContext

A Context carries a deadline, a cancelation Future, and other values across API boundaries.

Functions

background

Returns an empty Context. It is never canceled has neither a value nor a deadline. It is typically used as a top-level Context.

with_cancel

Returns a copy of parent as a new future, which is closed when the returned cancel function is called or when the parent context's future is resolved – whichever happens first.

with_deadline

Returns with_timeout(parent, deadline - Instant::now()).

with_timeout

Returns a copy of the parent context with the given deadline associated to it. The returned context's future resolves when the deadline expires, the returned cancel function is called, or when the parent context's future resolves – whichever happens first.

with_value

Returns a copy of parent, but with the given value associated to it.