pub struct ValidatedResponse<T> {
pub value: T,
pub config: ResponseModelConfig,
}Expand description
A validated response with its configuration.
This wraps a response value with its model configuration, ensuring the response is validated and filtered before sending.
§Examples
use fastapi_core::{ValidatedResponse, ResponseModelConfig};
use serde::Serialize;
#[derive(Serialize)]
struct User {
id: i64,
name: String,
email: String,
password_hash: String,
}
let user = User {
id: 1,
name: "Alice".to_string(),
email: "alice@example.com".to_string(),
password_hash: "secret123".to_string(),
};
// Create a validated response that excludes the password
let response = ValidatedResponse::new(user)
.with_config(ResponseModelConfig::new()
.exclude(["password_hash"].into_iter().map(String::from).collect()));Fields§
§value: TThe response value.
config: ResponseModelConfigThe serialization configuration.
Implementations§
Source§impl<T> ValidatedResponse<T>
impl<T> ValidatedResponse<T>
Sourcepub fn with_config(self, config: ResponseModelConfig) -> Self
pub fn with_config(self, config: ResponseModelConfig) -> Self
Set the serialization configuration.
Trait Implementations§
Source§impl<T: Debug> Debug for ValidatedResponse<T>
impl<T: Debug> Debug for ValidatedResponse<T>
Source§impl<T: Serialize + ResponseModel> IntoResponse for ValidatedResponse<T>
impl<T: Serialize + ResponseModel> IntoResponse for ValidatedResponse<T>
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Convert into a response.
Auto Trait Implementations§
impl<T> Freeze for ValidatedResponse<T>where
T: Freeze,
impl<T> RefUnwindSafe for ValidatedResponse<T>where
T: RefUnwindSafe,
impl<T> Send for ValidatedResponse<T>where
T: Send,
impl<T> Sync for ValidatedResponse<T>where
T: Sync,
impl<T> Unpin for ValidatedResponse<T>where
T: Unpin,
impl<T> UnwindSafe for ValidatedResponse<T>where
T: UnwindSafe,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).