Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add std support for no-std without global rand seed #169

Merged
merged 14 commits into from
Dec 17, 2024

Conversation

wackazong
Copy link
Contributor

Split #168 into two PRs as requested, this is the one for no_std support.

@wackazong wackazong mentioned this pull request Dec 1, 2024
@@ -12,3 +12,24 @@ pub use fibonacci::FibonacciBuilder;
mod exponential;
pub use exponential::ExponentialBackoff;
pub use exponential::ExponentialBuilder;

trait Random {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I don't want to introduce a new trait for this. Maybe we can store a new fastrand::Rng in every FibonacciBackoff?

@wackazong
Copy link
Contributor Author

Because of jitter, a random source is needed in all three Backoff Objects. That is why I used the trait. It is not just the FibonacciBackoff that needs randomness.

Considering this, I think it makes sense to use a trait in order to avoid duplication. But please, tell me how you want to proceed.

@wackazong
Copy link
Contributor Author

wackazong commented Dec 15, 2024

Reduced use of alloc to tests, this makes backon even better suitable for no_std

@Xuanwo
Copy link
Owner

Xuanwo commented Dec 16, 2024

Because of jitter, a random source is needed in all three Backoff Objects. That is why I used the trait. It is not just the FibonacciBackoff that needs randomness.

Thank you for the explanation.

But please, tell me how you want to proceed.

I think we can store a fastrand::Rng in FibonacciBackoff, which will be built when calling BackoffBuilder::build. If users don't provide one, we can rely on the global instance or use our own default value. For the default value, plese use 0x6261636b6f6e which is the hex output of backon in bytes.

With this change, we no longer need to differentiate between std and no-std.

@wackazong
Copy link
Contributor Author

I removed the trait and integrated the Rng as you suggested. Does this meet your expectations?

Copy link
Owner

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @wackazong for this! It mostly aligns with what I expected, with only a few minor suggestions.

backon/src/backoff/constant.rs Outdated Show resolved Hide resolved
backon/src/backoff/constant.rs Outdated Show resolved Hide resolved
backon/src/backoff/constant.rs Outdated Show resolved Hide resolved
backon/src/backoff/constant.rs Outdated Show resolved Hide resolved
backon/src/backoff/constant.rs Outdated Show resolved Hide resolved
backon/src/backoff/constant.rs Outdated Show resolved Hide resolved
backon/src/backoff/exponential.rs Outdated Show resolved Hide resolved
backon/src/backoff/exponential.rs Show resolved Hide resolved
backon/src/backoff/mod.rs Show resolved Hide resolved
Copy link
Owner

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @wackazong a lot for working on this. The only thing left is to address the merge conflicts.

backon/Cargo.toml Outdated Show resolved Hide resolved
backon/Cargo.toml Outdated Show resolved Hide resolved
@Xuanwo
Copy link
Owner

Xuanwo commented Dec 17, 2024

Hi @wackazong, the conflict persists even after 7668ec8 (#169). Please ensure your base is set to Xuanwo/main.

@wackazong
Copy link
Contributor Author

Ok, got it now.

Copy link
Owner

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @wackazong, let's move!

backon/Cargo.toml Outdated Show resolved Hide resolved
@Xuanwo Xuanwo changed the title No std support feat: Add std support for no-std without global rand seed Dec 17, 2024
@Xuanwo Xuanwo merged commit f7e3b97 into Xuanwo:main Dec 17, 2024
7 checks passed
wackazong added a commit to wackazong/backon that referenced this pull request Dec 17, 2024
Split Xuanwo#168 into two PRs as
requested, this is the one for no_std support.

---------

Co-authored-by: Xuanwo <[email protected]>
wackazong added a commit to wackazong/backon that referenced this pull request Dec 17, 2024
Split Xuanwo#168 into two PRs as
requested, this is the one for no_std support.

---------

Co-authored-by: Xuanwo <[email protected]>
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