Skip to content

Commit

Permalink
Remove duplicate example, point to examples on docs index page (#84)
Browse files Browse the repository at this point in the history
This PR is based on my own developer experience, of not knowing how to
make backon work with an async call that takes variable arguments.

To avoid having duplicate examples is various places, we rather point to
the documentation index page, where the main collection of examples
seems to be placed. This way hopefully developers can find the examples
they need to find, more easily.
  • Loading branch information
matildasmeds authored May 20, 2024
1 parent 7e90660 commit 97f24cc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
2 changes: 2 additions & 0 deletions examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use anyhow::Result;
use backon::ExponentialBuilder;
use backon::Retryable;

// For more examples, please see: https://docs.rs/backon/#examples

async fn fetch() -> Result<String> {
let response = reqwest::get("https://httpbingo.org/unstable?failure_rate=0.7").await?;
if !response.status().is_success() {
Expand Down
2 changes: 2 additions & 0 deletions examples/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use anyhow::Result;
use backon::BlockingRetryable;
use backon::ExponentialBuilder;

// For more examples, please see: https://docs.rs/backon/#examples

fn fetch() -> Result<String> {
Ok("hello, world!".to_string())
}
Expand Down
2 changes: 2 additions & 0 deletions examples/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use anyhow::Result;
use backon::BlockingRetryable;
use backon::ExponentialBuilder;

// For more examples, please see: https://docs.rs/backon/#examples

fn main() -> Result<()> {
let var = 42;
// `f` can use input variables
Expand Down
22 changes: 2 additions & 20 deletions src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,10 @@ use crate::Backoff;
/// }
/// ```
///
/// # Example
/// # Examples
///
/// ```no_run
/// use anyhow::Result;
/// use backon::ExponentialBuilder;
/// use backon::Retryable;
/// For more examples, please see: [https://docs.rs/backon/#examples](https://docs.rs/backon/#examples)
///
/// async fn fetch() -> Result<String> {
/// Ok(reqwest::get("https://www.rust-lang.org")
/// .await?
/// .text()
/// .await?)
/// }
///
/// #[tokio::main(flavor = "current_thread")]
/// async fn main() -> Result<()> {
/// let content = fetch.retry(&ExponentialBuilder::default()).await?;
/// println!("fetch succeeded: {}", content);
///
/// Ok(())
/// }
/// ```
pub trait Retryable<
B: BackoffBuilder,
T,
Expand Down

0 comments on commit 97f24cc

Please sign in to comment.