retry

A small Rust library to retry an operation until its return value satisfies a condition, with pluggable delays.

Library
Cargo
v2.2.0
125stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
42/100Fair
Development Activity4
Maintenance20
Community72
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture82
Code Quality80
Innovation72
Learning Curve86

retry is a focused Rust utility crate for retrying operations that can fail. You give it an iterator of delay durations and a closure, and it re-runs the closure until the closure signals success or the delay iterator is exhausted, returning the successful value or the last error.

The delay strategy is expressed as an ordinary iterator, so fixed intervals, exponential backoff, Fibonacci, and randomized jitter are all supported by composing standard iterator adapters. This keeps the API tiny while letting callers control the number of attempts, timing, and backoff behavior precisely.

What You Get

  • A retry function that runs an operation until it succeeds or delays are exhausted
  • Delay strategies as iterators: Fixed, Exponential, Fibonacci, Range, and NoDelay
  • A jitter adapter to randomize delays and avoid thundering-herd retries
  • OperationResult to distinguish retryable errors from permanent failures
  • A structured Error return carrying the last error and the total elapsed time/tries

Common Use Cases

  • Retrying a flaky network or I/O call with exponential backoff
  • Polling a resource until it becomes ready
  • Capping retries to a fixed number of attempts with fixed delays
  • Adding jitter to distributed retries to reduce contention

Under The Hood

Architecture - The crate’s core is a retry function that consumes an IntoIterator<Item = Duration> and an operation closure returning an OperationResult. It calls the operation, and on a retryable result sleeps for the next duration yielded by the delay iterator and tries again; it returns Ok on success, or an Error capturing the last failure, the number of tries, and the total delay once the iterator is exhausted. Delay strategies (Fixed, Exponential, Fibonacci, Range, NoDelay) are implemented as separate Iterator types under a delay module, and jitter is an adapter over any such iterator.

Tech Stack - 100% Rust with essentially no heavy dependencies (only rand for jitter). Distributed as the retry Cargo crate with comprehensive docs.rs documentation.

Code Quality - A long-lived crate (since 2015, 14 releases, 15 contributors, 16M+ downloads) that is small and stable. It carries a test suite and clear module separation between the retry engine and the delay iterators, though it is now in low-activity maintenance mode.

API Design - The design is elegant: because delays are ordinary iterators, callers compose behavior with familiar adapters (.take(n) to cap attempts, .map to transform, jitter to randomize) instead of learning a bespoke configuration API. OperationResult cleanly separates retryable from permanent errors, and the whole surface is small enough to learn in minutes.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search