| Crates.io | sdre-stubborn-io |
| lib.rs | sdre-stubborn-io |
| version | 0.6.11 |
| created_at | 2023-11-18 21:46:55.407427+00 |
| updated_at | 2025-08-10 06:58:37.463808+00 |
| description | Forked from https://github.com/craftytrickster/stubborn-io. io traits/structs that automatically recover from potential disconnections/interruptions. |
| homepage | |
| repository | https://github.com/sdr-enthusiasts/sdre-stubborn-io |
| max_upload_size | |
| id | 1040738 |
| size | 67,779 |
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 = { git = "https://github.com/sdr-enthusiasts/sdre-stubborn-io.git" }
This project has been forked from stubborn-io and modified to add the ability to name connections. Much thanks to craftytrickster for the original project.
API Documentation, examples and motivations can be found here - (Rust Docs)https://docs.rs/sdre-stubborn-io .
Only change to the documentation in this fork will be the addition of the ReconnectionOptions struct, which adds with_connection_name(name: &str) as a method to the StubbornTcpStream struct. This allows for the naming of the connection, which is useful for logging purposes.
If you generate the struct manually, the field name is connection_name.
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 sdre_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?;