fn retry<T, E>(f: impl Fn() -> Result<T, E>) -> Result<T, E> {
    let attempts = 30;
    let interval = Duration::from_millis(100);
    for attempt in (0..attempts).rev() {
        match f() {
            Ok(result) => return Ok(result),
            Err(e) if attempt == 0 => return Err(e),
            Err(_) => std::thread::sleep(interval),
        }
    }
    unreachable!()
}
/// Retry `f` 30 times 100ms apart, i.e. a total of three seconds.
///
/// When `f` returns an error wait 100ms and try it again, up to ten times.
/// If the last attempt failed return the error returned by that attempt.
///
/// If `f` returns Ok immediately return the result.
Retry `f` 30 times 100ms apart, i.e. a total of three seconds.
When `f` returns an error wait 100ms and try it again, up to ten times.
If the last attempt failed return the error returned by that attempt.

If `f` returns Ok immediately return the result.
Retry ` f ` 30 times 100ms apart i . e . a total of three seconds . When ` f ` returns an error wait 100ms and try it again up to ten times . If the last attempt failed return the error returned by that attempt . If ` f ` returns Ok immediately return the result .
fn retry<T, E>(f: impl Fn() -> Result<T, E>) -> Result<T, E> {
    let attempts = 30;
    let interval = Duration::from_millis(100);
    for attempt in (0..attempts).rev() {
        match f() {
            Ok(result) => return Ok(result),
            Err(e) if attempt == 0 => return Err(e),
            Err(_) => std::thread::sleep(interval),
        }
    }
    unreachable!()
}
fn retry < T , E > ( f : impl Fn ( ) -> Result < T , E > ) -> Result < T , E > { let attempts = 30 ; let interval = Duration :: from_millis ( 100 ) ; for attempt in ( 0 .. attempts ) . rev ( ) { match f ( ) { Ok ( result ) => return Ok ( result ) , Err ( e ) if attempt == 0 => return Err ( e ) , Err ( _ ) => std :: thread :: sleep ( interval ) , } } unreachable ! ( ) }
Retry `f` 30 times 100ms apart, i.e.
Retry ` f ` 30 times 100ms apart i . e .
f
impl Fn() -> Result<T, E>