tui-realm
tui-realm copied to clipboard
[Feature Request] - Change ports to make use of `Iterator` and `Stream`
Description
Currently Poll and PollAsync make use of custom function signatures, but from usage and expectations they would be more in-line with using Iterators for Poll and (futures_util::)Stream with PollAsync
Changes
We could either:
- completely remove those 2 traits and make them a alias to
Iterator<Item = Result<Event, Error>>andStream<Item = Result<Event, Error>>, or - keep the traits, but make them a default impl and require
Iterator/Streamto be implemented, similar to howrodiohandlesSourceandSamples
Implementation
Either:
pub type Poll<UserEvent: Eq + PartialEq + Clone + PartialOrd + 'static> = Iterator<Item = ListenerResult<Event<UserEvent>>> + Send;
pub type PollAsync<UserEvent: Eq + PartialEq + Clone + PartialOrd + 'static> = futures_util::Stream<Item = ListenerResult<Event<UserEvent>>> + Send;
or
pub trait Poll<UserEvent>: Iterator<Item = ListenerResult<Event<UserEvent>>> + Send
where
UserEvent: Eq + PartialEq + Clone + PartialOrd + 'static,
{
fn poll(&mut self) -> ListenerResult<Option<Event<UserEvent>>> {
self.next().transpose()
}
}
pub trait PollAsync<UserEvent>: futures_util::Stream<Item = ListenerResult<Event<UserEvent>>> + Send
where
UserEvent: Eq + PartialEq + Clone + PartialOrd + Send + 'static,
{
async fn poll(&mut self) -> ListenerResult<Option<Event<UserEvent>>> {
self.next().await.transpose()
}
}
(we could also avoid the transposes by changing our signatures, which i would actually recommend)
PS: if the Poll and PollAsync types are not expected to actually get any extra functions, i would actually recommend going with the type aliases.