pub struct Ctx<D, A = Public> { /* private fields */ }Expand description
The per-request context. Cheap to clone; hooks and event handlers get their own copy.
Implementations§
Source§impl<D: Adapter, A> Ctx<D, A>
impl<D: Adapter, A> Ctx<D, A>
Sourcepub fn db_on<'t, Q: Queries>(&'t self, queries: &'t Q) -> Db<'t, Q>
pub fn db_on<'t, Q: Queries>(&'t self, queries: &'t Q) -> Db<'t, Q>
Typed queries inside a transaction: let tx = ctx.adapter().begin().await?; ctx.db_on(&tx).
Sourcepub fn adapter(&self) -> &D
pub fn adapter(&self) -> &D
The adapter this call runs on: the configured one, or the one a server API call
passed to Api::within (for sqlx, one bound to the app’s transaction).
pub fn schema(&self) -> &Schema
pub fn keys(&self) -> &Keys
pub fn config(&self) -> &CoreConfig
pub fn passwords(&self) -> &Passwords
pub fn now(&self) -> OffsetDateTime
Sourcepub fn new_id(&self) -> Result<Id, AuthError>
pub fn new_id(&self) -> Result<Id, AuthError>
A new id from the configured IdStrategy. Fails only
when a custom generator returns an invalid id: a 500 whose detail is logged.
pub fn request(&self) -> &RequestInfo
pub fn headers(&self) -> &HeaderMap
pub fn ip(&self) -> Option<&str>
pub fn user_agent(&self) -> Option<&str>
Sourcepub fn param(&self, name: &str) -> Option<&str>
pub fn param(&self, name: &str) -> Option<&str>
A path parameter, e.g. {token} in /reset-password/{token}.
Sourcepub fn plugin<P: Plugin>(&self) -> &P
pub fn plugin<P: Plugin>(&self) -> &P
A plugin’s config. Panics if it isn’t registered, which Plugin::Requires rules out
for dependencies. Use try_plugin for optional ones.
pub fn try_plugin<P: Plugin>(&self) -> Option<&P>
Sourcepub fn emit<E: Event>(&self, event: E)
pub fn emit<E: Event>(&self, event: E)
Queues an event; handlers run after the endpoint succeeds.
Sets {prefix}.{name}, signed with the cookie key.
Reads {prefix}.{name} and checks its signature.