use std::pin::Pin;
use std::task::{Context, Poll};
use crate::error::AgentError;
use crate::event::AgentEvent;
use futures_core::Stream;
pub struct AgentStream<S> {
inner: Pin<Box<S>>,
}
impl<S> AgentStream<S>
where
S: Stream<Item = Result<AgentEvent, AgentError>>,
{
pub fn new(inner: S) -> Self {
Self {
inner: Box::pin(inner),
}
}
}
impl<S> Stream for AgentStream<S>
where
S: Stream<Item = Result<AgentEvent, AgentError>>,
{
type Item = Result<AgentEvent, AgentError>;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.inner.as_mut().poll_next(cx)
}
}
impl<S> std::fmt::Debug for AgentStream<S> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AgentStream").finish()
}
}