pub struct Context {
pub input: Map<String, Value>,
pub data: Option<Value>,
pub user: Option<AuthenticatedUser>,
pub pool: PgPool,
pub headers: HashMap<String, String>,
pub response_headers: Vec<(String, String)>,
}Expand description
Context passed to controller functions for synchronous in-request business logic.
Controllers receive a mutable Context and can:
- Modify
inputbefore the DB operation (before-controllers) - Read/modify
dataafter the DB operation (after-controllers) - Return
Err(...)to halt the request with an error response
§Example
ⓘ
pub async fn validate_org(ctx: &mut Context) -> Result<(), ShaperailError> {
if let Some(email) = ctx.input.get("email").and_then(|v| v.as_str()) {
ctx.input["email"] = serde_json::json!(email.to_lowercase());
}
Ok(())
}Fields§
§input: Map<String, Value>Mutable input data. Before-controllers can modify what gets written to DB.
data: Option<Value>DB result data. None in before-controllers, Some(...) in after-controllers.
user: Option<AuthenticatedUser>The authenticated user, if present.
pool: PgPoolDatabase pool for custom queries within the controller.
headers: HashMap<String, String>Request headers (read-only).
response_headers: Vec<(String, String)>Extra response headers the controller wants to add.
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl !UnwindSafe 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
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request