Crates.io | keen-retry |
lib.rs | keen-retry |
version | 0.5.0 |
source | src |
created_at | 2023-07-26 03:46:49.692006 |
updated_at | 2024-08-20 05:11:51.531164 |
description | A simple -- yet powerful -- zero-cost-abstractions & zero-copy lib for error handling & recovery |
homepage | https://github.com/zertyz/keen-retry |
repository | https://github.com/zertyz/keen-retry |
max_upload_size | |
id | 926192 |
size | 10,400,336 |
The keen-retry
crate is designed to provide a zero-cost, flexible, and robust way to implement retry logic in Rust applications, while also
supporting adding resiliency to libraries. Whether you are developing an API, a high-performance system, a distributed application, or a simple
tool, keen-retry
offers a comprehensive set of features to handle transient failures gracefully, ensuring your application remains resilient,
reliable and is able to provide rich diagnostic messages, indispensable for addressing the root cause of failures.
The first step is to have every retryable operation from your Library or API returning the enriched RetryResult
type, which clearly discriminates between Ok
, Fatal
and Transient
variants:
/// Wrapper around [Self::connect_to_server_raw()], enabling `keen-retry` on it
pub async fn connect_to_server(&self) -> RetryProcedureResult<ConnectionErrors> {
self.connect_to_server_raw().await
.map_or_else(|error| match error.is_fatal() {
true => RetryResult::Fatal { input: (), error },
false => RetryResult::Transient { input: (), error },
},
|_| RetryResult::Ok { reported_input: (), output: () })
}
Now, in the application, you may use it via the zero-cost functional API:
let resolved = connect_to_server()
.retry_with(|_| connect_to_server())
.<one-of-the-backoff-strategies>(...)
.<instrumentation-facilities>(...)
.<mapping-of-outputs-and-errors>(...);
keen-retry
DiagramFor more details, please refer to tests/use_cases.rs
, which contains advanced
demonstrations such as how to add a fully fledged instrumentation (as seen in production applications),
how to compose nested retry logics and how to implement the versatile "Partial Completion with Continuation
Closure" design pattern.
keen-retry
has been rigorously benchmarked to ensure it adheres to the zero-cost abstraction principle, crucial in systems programming.
Our benchmarks, available at benches/zero_cost_abstractions.rs
, demonstrate the efficiency of the crate.
For a deep dive into the applicable Design Patterns, principles, strategies, and best practices for using keen-retry
effectively,
be sure to explore our companion keen-retry crate's Book, which serves as a definitive guide, providing insights and practical
examples to harness the full potential of keen-retry
in various software development scenarios.