Struct poem_openapi::payload::EventStream
source · [−]pub struct EventStream<T: Stream + Send + 'static> { /* private fields */ }
Expand description
An event stream payload.
Reference: https://github.com/OAI/OpenAPI-Specification/issues/396#issuecomment-894718960
Implementations
sourceimpl<T: Stream + Send + 'static> EventStream<T>
impl<T: Stream + Send + 'static> EventStream<T>
sourcepub fn keep_alive(self, duration: Duration) -> Self
pub fn keep_alive(self, duration: Duration) -> Self
Set the keep alive interval.
sourcepub fn to_event(self, f: impl FnMut(T::Item) -> Event + Send + 'static) -> Self
pub fn to_event(self, f: impl FnMut(T::Item) -> Event + Send + 'static) -> Self
Set a function used to convert the message to SSE event.
Examples
use poem::web::sse::Event;
use poem_openapi::{payload::EventStream, types::ToJSON, Object};
#[derive(Debug, Object)]
struct MyEvent {
value: i32,
}
EventStream::new(futures_util::stream::iter(vec![
MyEvent { value: 1 },
MyEvent { value: 2 },
MyEvent { value: 3 },
]))
.to_event(|event| {
let json = event.to_json_string();
Event::message(json).event_type("push")
});
Trait Implementations
sourceimpl<T: Stream<Item = E> + Send + 'static, E: Type + ToJSON> ApiResponse for EventStream<T>
impl<T: Stream<Item = E> + Send + 'static, E: Type + ToJSON> ApiResponse for EventStream<T>
sourcefn register(registry: &mut Registry)
fn register(registry: &mut Registry)
Register the schema contained in this response object to the registry.
sourceconst BAD_REQUEST_HANDLER: bool = false
const BAD_REQUEST_HANDLER: bool = false
If true, it means that the response object has a custom bad request
handler. Read more
sourcefn from_parse_request_error(err: Error) -> Self
fn from_parse_request_error(err: Error) -> Self
Convert
poem::Error
to this response object.sourceimpl<T: Stream<Item = E> + Send + 'static, E: Type + ToJSON + 'static> IntoResponse for EventStream<T>
impl<T: Stream<Item = E> + Send + 'static, E: Type + ToJSON + 'static> IntoResponse for EventStream<T>
sourcefn into_response(self) -> Response
fn into_response(self) -> Response
Consume itself and return
Response
.sourcefn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self>where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self>where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Wrap an
impl IntoResponse
to add a header. Read moresourcefn with_content_type<V>(self, content_type: V) -> WithContentType<Self>where
V: TryInto<HeaderValue>,
fn with_content_type<V>(self, content_type: V) -> WithContentType<Self>where
V: TryInto<HeaderValue>,
Wrap an
impl IntoResponse
to with a new content type. Read moresourcefn with_status(self, status: StatusCode) -> WithStatus<Self>
fn with_status(self, status: StatusCode) -> WithStatus<Self>
Wrap an
impl IntoResponse
to set a status code. Read moresourceimpl<T: Stream<Item = E> + Send + 'static, E: Type + ToJSON> Payload for EventStream<T>
impl<T: Stream<Item = E> + Send + 'static, E: Type + ToJSON> Payload for EventStream<T>
sourceconst CONTENT_TYPE: &'static str = "text/event-stream"
const CONTENT_TYPE: &'static str = "text/event-stream"
The content type of this payload.
sourcefn schema_ref() -> MetaSchemaRef
fn schema_ref() -> MetaSchemaRef
Gets schema reference of this payload.
sourcefn register(registry: &mut Registry)
fn register(registry: &mut Registry)
Register the schema contained in this payload to the registry.
sourcefn check_content_type(content_type: &str) -> bool
fn check_content_type(content_type: &str) -> bool
Check the content type of incoming request
Auto Trait Implementations
impl<T> !RefUnwindSafe for EventStream<T>
impl<T> Send for EventStream<T>
impl<T> !Sync for EventStream<T>
impl<T> Unpin for EventStream<T>where
T: Unpin,
impl<T> !UnwindSafe for EventStream<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoResult<T> for Twhere
T: IntoResponse,
impl<T> IntoResult<T> for Twhere
T: IntoResponse,
sourcefn into_result(self) -> Result<T, Error>
fn into_result(self) -> Result<T, Error>
Consumes this value returns a
poem::Result<T>
.