pub struct Context { /* private fields */ }Expand description
Per-request context passed to every action.
Implementations§
Source§impl Context
impl Context
Sourcepub async fn build(req: Request) -> Self
pub async fn build(req: Request) -> Self
Central constructor used by the #[controller] macro. Splits the request,
captures matched path params, and retains the body for later reads.
pub fn from_request_parts(parts: Parts) -> Self
pub fn from_request(parts: Parts, body: Body) -> Self
Sourcepub fn db(&self) -> &'static DatabaseConnection
pub fn db(&self) -> &'static DatabaseConnection
The application’s database connection (global pool installed at boot).
Sourcepub fn param(&self, name: &str) -> Option<&str>
pub fn param(&self, name: &str) -> Option<&str>
A matched path parameter by name, e.g. ctx.param("id") for /posts/{id}.
Sourcepub async fn form<T: DeserializeOwned>(&mut self) -> Result<T>
pub async fn form<T: DeserializeOwned>(&mut self) -> Result<T>
Deserialize a URL-encoded (form) request body. Consumes the body.
Sourcepub async fn body_json<T: DeserializeOwned>(&mut self) -> Result<T>
pub async fn body_json<T: DeserializeOwned>(&mut self) -> Result<T>
Deserialize a JSON request body. Consumes the body.
Sourcepub fn params<T: DeserializeOwned>(&self) -> Result<T>
pub fn params<T: DeserializeOwned>(&self) -> Result<T>
Deserialize typed params from the request URI query string.
Sourcepub fn render(&self, template: &str, data: Value) -> Response
pub fn render(&self, template: &str, data: Value) -> Response
Render a Tera view to an HTML 200 response.
template is resolved by the global doido_view engine (installed at
boot) against app/views, with the .html.tera suffix added — e.g.
"posts/index" → app/views/posts/index.html.tera. A render failure (or
an uninitialised engine) yields a 500.
Sourcepub fn redirect_to(&self, location: impl AsRef<str>) -> Response
pub fn redirect_to(&self, location: impl AsRef<str>) -> Response
Return a 302 redirect.
Sourcepub fn status(&self, code: u16) -> Response
pub fn status(&self, code: u16) -> Response
Return a response with an explicit status code and empty body.
code must be a valid HTTP status code (100–999).
Sourcepub fn header(&self, name: &str) -> Option<&HeaderValue>
pub fn header(&self, name: &str) -> Option<&HeaderValue>
Get a request header by name (lowercase).
Auto Trait Implementations§
impl !Freeze for Context
impl !RefUnwindSafe for Context
impl !Sync for Context
impl !UnwindSafe for Context
impl Send for Context
impl Unpin for Context
impl UnsafeUnpin for Context
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more