Struct gotham_restful::Response
source · pub struct Response { /* private fields */ }
Expand description
A response, used to create the final gotham response from.
This type is not meant to be used as the return type of endpoint handlers. While it can be
freely used without the openapi
feature, it is more complicated to use when you enable it,
since this type does not store any schema information. You can attach schema information
like so:
fn schema(code: StatusCode) -> OpenapiSchema {
assert_eq!(code, StatusCode::ACCEPTED);
<()>::schema()
}
fn status_codes() -> Vec<StatusCode> {
vec![StatusCode::ACCEPTED]
}
#[create(schema = "schema", status_codes = "status_codes")]
fn create(body: Raw<Vec<u8>>) {}
Implementations§
source§impl Response
impl Response
sourcepub fn new<B: Into<Body>>(
status: StatusCode,
body: B,
mime: Option<Mime>
) -> Self
pub fn new<B: Into<Body>>( status: StatusCode, body: B, mime: Option<Mime> ) -> Self
Create a new Response from raw data.
sourcepub fn json<B: Into<Body>>(status: StatusCode, body: B) -> Self
pub fn json<B: Into<Body>>(status: StatusCode, body: B) -> Self
Create a Response with mime type json from already serialized data.
sourcepub fn no_content() -> Self
pub fn no_content() -> Self
Create a 204 No Content Response.
sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Return the status code of this Response.
sourcepub fn header(&mut self, name: HeaderName, value: HeaderValue)
pub fn header(&mut self, name: HeaderName, value: HeaderValue)
Add an HTTP header to the Response.
Trait Implementations§
source§impl IntoResponse for Response
impl IntoResponse for Response
type Err = Infallible
Auto Trait Implementations§
impl !RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl !UnwindSafe for Response
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more