This file provides guidance to AI coding agents when working with code in this repository.
BackON is a Rust retry library that provides a fluent API for implementing retry logic with various backoff strategies. The library supports both synchronous and asynchronous operations, with cross-platform support including WASM and no_std environments.
-
Backoff Strategies (
backon/src/backoff/): Different retry timing strategiesExponentialBackoff: Exponential backoff with optional jitterConstantBackoff: Fixed delay between retriesFibonacciBackoff: Fibonacci sequence-based delays- All implement the
Backofftrait defined inapi.rs
-
Sleep Implementations (
backon/src/sleep.rs,backon/src/blocking_sleep.rs): Platform-specific sleep implementations- Async sleepers:
TokioSleeper,GlooTimersSleep,FutureTimerSleep,EmbassySleeper - Blocking sleepers:
StdSleeper - All sleepers implement
SleeperorBlockingSleepertraits
- Async sleepers:
-
Retry Logic (
backon/src/retry.rs,backon/src/blocking_retry.rs): Core retry functionalityRetryabletrait for async functionsBlockingRetryabletrait for sync functionsRetryableWithContextfor functions that need mutable context
-
Features: Conditional compilation based on target and enabled features
- Default features enable common sleepers for different platforms
- WASM-specific implementations using
gloo-timers - Embassy support for embedded environments
# Check code for errors
cargo check
# Build the project
cargo build
# Run linting (clippy)
cargo clippy
# Run tests
cargo test
# Run benchmarks
cargo bench
# Format code
cargo fmt- Unit tests are in each module alongside the implementation
- Integration tests demonstrate real-world usage patterns
- WASM tests use
wasm-bindgen-test - Platform-specific tests are gated by target architecture
- Builder pattern for backoff strategies (e.g.,
ExponentialBuilder::default()) - Trait-based design for extensibility (
Backoff,Sleeper,Retryable) - Feature-gated implementations for different platforms
- Zero-cost abstractions with compile-time feature selection
- No-std compatibility with optional std features