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
pub fn new_id(&self) -> Id
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.
pub fn set_header(&self, name: HeaderName, value: HeaderValue)
Source§impl<D: Adapter> Ctx<D, MaybeAuthenticated>
impl<D: Adapter> Ctx<D, MaybeAuthenticated>
pub fn session(&self) -> Option<&SessionView>
Source§impl<D: Adapter> Ctx<D, Authenticated>
impl<D: Adapter> Ctx<D, Authenticated>
pub fn session(&self) -> &SessionView
Trait Implementations§
Auto Trait Implementations§
impl<D, A = Public> !RefUnwindSafe for Ctx<D, A>
impl<D, A = Public> !UnwindSafe for Ctx<D, A>
impl<D, A> Forget for Ctx<D, A>
impl<D, A> Freeze for Ctx<D, A>
impl<D, A> Move for Ctx<D, A>
impl<D, A> Send for Ctx<D, A>
impl<D, A> Sync for Ctx<D, A>
impl<D, A> Unpin for Ctx<D, A>
impl<D, A> UnsafeUnpin for Ctx<D, A>where
Arc<Shared<D>>: UnsafeUnpin,
Option<Arc<D>>: UnsafeUnpin,
PhantomData<fn() -> A>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more