Skip to content

Commit

Permalink
stream.rs: Eliminate the redundant Clock+ReasonablyRealtime bounds
Browse files Browse the repository at this point in the history
They indicated the same thing and resulted in weird-to-read type
signatures, and only in the StreamRateLimitExt trait, too: Drop the
Clock bound, and only use ReasonablyRealtime.
  • Loading branch information
antifuchs committed Jun 10, 2024
1 parent 58577c8 commit 84c36e7
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions governor/src/state/direct/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ pub trait StreamRateLimitExt<'a>: Stream {
/// it will not `poll` the underlying stream.
fn ratelimit_stream<
D: DirectStateStore,
C: clock::Clock,
C: clock::ReasonablyRealtime,
MW: RateLimitingMiddleware<C::Instant>,
>(
self,
limiter: &'a RateLimiter<NotKeyed, D, C, MW>,
) -> RatelimitedStream<'a, Self, D, C, MW>
where
Self: Sized,
C: clock::ReasonablyRealtime;
Self: Sized;

/// Limits the rate at which the stream produces items, with a randomized wait period.
///
Expand All @@ -43,37 +42,35 @@ pub trait StreamRateLimitExt<'a>: Stream {
/// it will not `poll` the underlying stream.
fn ratelimit_stream_with_jitter<
D: DirectStateStore,
C: clock::Clock,
C: clock::ReasonablyRealtime,
MW: RateLimitingMiddleware<C::Instant>,
>(
self,
limiter: &'a RateLimiter<NotKeyed, D, C, MW>,
jitter: Jitter,
) -> RatelimitedStream<'a, Self, D, C, MW>
where
Self: Sized,
C: clock::ReasonablyRealtime;
Self: Sized;
}

impl<'a, S: Stream> StreamRateLimitExt<'a> for S {
fn ratelimit_stream<
D: DirectStateStore,
C: clock::Clock,
C: clock::ReasonablyRealtime,
MW: RateLimitingMiddleware<C::Instant>,
>(
self,
limiter: &'a RateLimiter<NotKeyed, D, C, MW>,
) -> RatelimitedStream<'a, Self, D, C, MW>
where
Self: Sized,
C: clock::ReasonablyRealtime,
{
self.ratelimit_stream_with_jitter(limiter, Jitter::NONE)
}

fn ratelimit_stream_with_jitter<
D: DirectStateStore,
C: clock::Clock,
C: clock::ReasonablyRealtime,
MW: RateLimitingMiddleware<C::Instant>,
>(
self,
Expand All @@ -82,7 +79,6 @@ impl<'a, S: Stream> StreamRateLimitExt<'a> for S {
) -> RatelimitedStream<'a, Self, D, C, MW>
where
Self: Sized,
C: clock::ReasonablyRealtime,
{
RatelimitedStream {
inner: self,
Expand Down

0 comments on commit 84c36e7

Please # to comment.