pub enum Response<T> {
Body(T),
WithStatus(StatusCode, T),
Raw(StatusCode, Body),
Empty,
}Variants§
Implementations§
Source§impl Response<()>
impl Response<()>
pub fn no_content() -> Self
pub fn text(status: StatusCode, value: impl Into<String>) -> Self
pub fn bytes(status: StatusCode, value: impl Into<Vec<u8>>) -> Self
pub fn json(status: StatusCode, value: impl Serialize) -> Self
Sourcepub fn stream(
content_type: &'static str,
stream: impl Stream<Item = Result<Bytes>> + Send + 'static,
) -> HttpResponse
pub fn stream( content_type: &'static str, stream: impl Stream<Item = Result<Bytes>> + Send + 'static, ) -> HttpResponse
Stream response chunks as they become ready (chunked transfer encoding is applied by the HTTP adapter).
Sourcepub fn sse<T>(
stream: impl Stream<Item = Result<T>> + Send + 'static,
) -> HttpResponsewhere
T: Serialize + 'static,
pub fn sse<T>(
stream: impl Stream<Item = Result<T>> + Send + 'static,
) -> HttpResponsewhere
T: Serialize + 'static,
Server-Sent Events: each item is serialized as JSON and framed as
data: <json>\n\n with content type text/event-stream.
Also sets Cache-Control: no-cache and X-Accel-Buffering: no so
proxies/browsers do not buffer the stream. Does not yet implement the
full SSE protocol (id:, event:, retry:, Last-Event-ID).
Trait Implementations§
Source§impl<T: Serialize> IntoCaelixResponse for Response<T>
impl<T: Serialize> IntoCaelixResponse for Response<T>
fn into_response(self) -> HttpResponse
Auto Trait Implementations§
impl<T> Freeze for Response<T>where
T: Freeze,
impl<T> RefUnwindSafe for Response<T>where
T: RefUnwindSafe,
impl<T> Send for Response<T>where
T: Send,
impl<T> Sync for Response<T>where
T: Sync,
impl<T> Unpin for Response<T>where
T: Unpin,
impl<T> UnsafeUnpin for Response<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Response<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: 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 more