Remove generic Hasher and Event from subscription::Recipe

This commit is contained in:
Héctor Ramón Jiménez 2023-03-05 04:15:10 +01:00
parent 5fed065dc3
commit f4cf488e0b
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
20 changed files with 341 additions and 406 deletions

View file

@ -18,28 +18,26 @@ impl crate::Executor for Executor {
pub mod time {
//! Listen and react to time.
use crate::core::Hasher;
use crate::subscription::{self, Subscription};
/// Returns a [`Subscription`] that produces messages at a set interval.
///
/// The first message is produced after a `duration`, and then continues to
/// produce more messages every `duration` after that.
pub fn every<H: std::hash::Hasher, E>(
pub fn every(
duration: std::time::Duration,
) -> Subscription<H, E, std::time::Instant> {
) -> Subscription<std::time::Instant> {
Subscription::from_recipe(Every(duration))
}
#[derive(Debug)]
struct Every(std::time::Duration);
impl<H, E> subscription::Recipe<H, E> for Every
where
H: std::hash::Hasher,
{
impl subscription::Recipe for Every {
type Output = std::time::Instant;
fn hash(&self, state: &mut H) {
fn hash(&self, state: &mut Hasher) {
use std::hash::Hash;
std::any::TypeId::of::<Self>().hash(state);
@ -48,7 +46,7 @@ pub mod time {
fn stream(
self: Box<Self>,
_input: futures::stream::BoxStream<'static, E>,
_input: subscription::EventStream,
) -> futures::stream::BoxStream<'static, Self::Output> {
use futures::stream::StreamExt;