Skip to content

feat: no_std support#5

Merged
brayniac merged 7 commits intoiopsystems:mainfrom
zeon256:main
Apr 21, 2026
Merged

feat: no_std support#5
brayniac merged 7 commits intoiopsystems:mainfrom
zeon256:main

Conversation

@zeon256
Copy link
Copy Markdown
Contributor

@zeon256 zeon256 commented Mar 23, 2026

Hello!

This PR seeks to make the crate #[no_std] first with std as the default feature. This is because most of the crate can use the things in core with the exception of Instant. This PR makes Ratelimiter generic over Clock and provides StdClock for users that want to use std. I have made changes to the test as well to not rely on sleep

@brayniac
Copy link
Copy Markdown
Contributor

This mostly looks reasonable. I'll make some changes on top of this before release to avoid the type breakage and the builder pattern breakage.

Thanks for the contribution

@brayniac brayniac merged commit 87f2829 into iopsystems:main Apr 21, 2026
6 of 7 checks passed
brayniac added a commit that referenced this pull request Apr 21, 2026
* fix: expose Builder::with_clock and add Default for StdClock

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>

* feat: default Clock type parameter to StdClock

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>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

2 participants