poem_grpc/
streaming.rs

1use std::{
2    pin::Pin,
3    task::{Context, Poll},
4};
5
6use futures_util::{Stream, StreamExt, stream::BoxStream};
7
8use crate::Status;
9
10/// Message stream
11pub struct Streaming<T>(BoxStream<'static, Result<T, Status>>);
12
13impl<T> Streaming<T> {
14    /// Create a message stream
15    #[inline]
16    pub fn new<S>(stream: S) -> Self
17    where
18        S: Stream<Item = Result<T, Status>> + Send + 'static,
19    {
20        Self(stream.boxed())
21    }
22}
23
24impl<T> Stream for Streaming<T> {
25    type Item = Result<T, Status>;
26
27    #[inline]
28    fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
29        self.0.poll_next_unpin(cx)
30    }
31}