fix: no_std ergonomic follow-ups to #5#9
Merged
Conversation
Builder::with_clock was pub(crate), leaving no_std users without a way to build a Ratelimiter with custom max_tokens or initial_available — the only public no_std constructor was Ratelimiter::with_clock, which takes neither. Make it pub and document it. Also add impl Default for StdClock to satisfy clippy::new_without_default and pair the ergonomic new() constructor with a Default impl. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Make the Clock generic default to StdClock when the std feature is enabled, so callers can name Ratelimiter and Builder without generics in type position — e.g. fn foo(rl: &Ratelimiter) stays valid. Because StdClock itself is gated by #[cfg(feature = "std")], the default can't be expressed unconditionally; the struct declarations for Ratelimiter and Builder are cfg-duplicated with and without the default. The impl blocks are unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Post-merge cleanup for #5. Three small, independent fixes.
Builder::with_clock— it waspub(crate), leaving no_std users with no way to setmax_tokensorinitial_available(onlyRatelimiter::with_clockwas reachable, which takes neither).impl Default for StdClock— pairs thenew()constructor with aDefaultimpl and silencesclippy::new_without_default.Clockgeneric toStdClock— preserves source compat forfn foo(rl: &Ratelimiter)-style signatures. TheStdClocktype is#[cfg]-gated, so the default can only be expressed in the std build; the struct declarations forRatelimiterandBuilderare#[cfg]-duplicated (impl blocks unaffected).Changes
Test plan
cargo test/cargo test --release— 25 tests pass (newtype_default_clocktest proves the default works in type position)cargo clippy --all-targets -- -D warningscargo check --no-default-featurescargo clippy --no-default-features --lib -- -D warningscargo fmt --all -- --checkRUSTDOCFLAGS=\"-D warnings\" cargo doc --no-deps🤖 Generated with Claude Code