#reconnect #retry #io #stubborn #stubborn-tcp-stream

stubborn-io

io traits/structs that automatically recover from potential disconnections/interruptions

16 releases

0.3.2 Sep 30, 2022
0.3.1 Jan 5, 2021
0.3.0 Dec 26, 2020
0.2.1 Oct 16, 2020
0.1.0 Jul 31, 2019

#4 in #retry

Download history 5778/week @ 2023-06-06 5990/week @ 2023-06-13 6254/week @ 2023-06-20 5012/week @ 2023-06-27 4907/week @ 2023-07-04 4166/week @ 2023-07-11 5005/week @ 2023-07-18 5023/week @ 2023-07-25 3667/week @ 2023-08-01 4378/week @ 2023-08-08 4926/week @ 2023-08-15 5143/week @ 2023-08-22 3917/week @ 2023-08-29 4337/week @ 2023-09-05 4527/week @ 2023-09-12 3380/week @ 2023-09-19

17,029 downloads per month
Used in xain-fl

MIT license

30KB
535 lines

stubborn-io

This crate provides io traits/structs that automatically recover from potential disconnections/interruptions.

To use with your project, add the following to your Cargo.toml:

stubborn-io = "0.3"

API Documentation, examples and motivations can be found here - https://docs.rs/stubborn-io .

Note: This crate requires at least version 1.39 of the Rust compiler.

Usage Example

In this example, we will see a drop in replacement for tokio's TcpStream, with the distinction that it will automatically attempt to reconnect in the face of connectivity failures.

use stubborn_io::StubbornTcpStream;
use tokio::io::AsyncWriteExt;

let addr = "localhost:8080";

async {
    // we are connecting to the TcpStream using the default built in options.
    // these can also be customized (for example, the amount of reconnect attempts,
    // wait duration, etc) using the connect_with_options method.
    let mut tcp_stream = StubbornTcpStream::connect(addr).await.unwrap();
    // once we acquire the wrapped IO, in this case, a TcpStream, we can
    // call all of the regular methods on it, as seen below
    tcp_stream.write_all(b"hello world!").await.unwrap();
};

Dependencies

~3–12MB
~112K SLoC