Crates.io | stubborn-io |
lib.rs | stubborn-io |
version | 0.3.5 |
source | src |
created_at | 2019-07-31 22:41:08.523215 |
updated_at | 2024-05-08 00:04:04.967681 |
description | io traits/structs that automatically recover from potential disconnections/interruptions. |
homepage | |
repository | https://github.com/craftytrickster/stubborn-io |
max_upload_size | |
id | 153290 |
size | 43,116 |
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 .
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";
// 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?;
// 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?;