Skip to content

fix: no_std ergonomic follow-ups to #5#9

Merged
brayniac merged 2 commits into
iopsystems:mainfrom
brayniac:no-std-fixup
Apr 21, 2026
Merged

fix: no_std ergonomic follow-ups to #5#9
brayniac merged 2 commits into
iopsystems:mainfrom
brayniac:no-std-fixup

Conversation

@brayniac
Copy link
Copy Markdown
Contributor

Summary

Post-merge cleanup for #5. Three small, independent fixes.

  • Expose Builder::with_clock — it was pub(crate), leaving no_std users with no way to set max_tokens or initial_available (only Ratelimiter::with_clock was reachable, which takes neither).
  • Add impl Default for StdClock — pairs the new() constructor with a Default impl and silences clippy::new_without_default.
  • Default the Clock generic to StdClock — preserves source compat for fn foo(rl: &Ratelimiter)-style signatures. The StdClock type is #[cfg]-gated, so the default can only be expressed in the std build; the struct declarations for Ratelimiter and Builder are #[cfg]-duplicated (impl blocks unaffected).

Changes

  • d898d43 fix: expose Builder::with_clock and add Default for StdClock
  • 0e829a3 feat: default Clock type parameter to StdClock

Test plan

  • cargo test / cargo test --release — 25 tests pass (new type_default_clock test proves the default works in type position)
  • cargo clippy --all-targets -- -D warnings
  • cargo check --no-default-features
  • cargo clippy --no-default-features --lib -- -D warnings
  • cargo fmt --all -- --check
  • RUSTDOCFLAGS=\"-D warnings\" cargo doc --no-deps

🤖 Generated with Claude Code

brayniac and others added 2 commits April 21, 2026 10:54
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>
@brayniac brayniac merged commit 78750bb into iopsystems:main Apr 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant