Struct ReconnectOptions

Source
pub struct ReconnectOptions(/* private fields */);
Expand description

User specified options that control the behavior of the ReconnectStream upon disconnect.

Implementations§

Source§

impl ReconnectOptions

Source

pub fn new() -> Self

By default, the ReconnectStream will not try to reconnect if the first connect attempt fails. By default, the retries iterator waits longer and longer between reconnection attempts, until it eventually perpetually tries to reconnect every 30 minutes.

Source

pub fn with_retries_generator<F, I, IN>(self, retries_generator: F) -> Self
where F: 'static + Send + Sync + Fn() -> IN, I: 'static + Send + Sync + Iterator<Item = Duration>, IN: IntoIterator<IntoIter = I, Item = Duration>,

Represents a function that generates an Iterator to schedule the wait between reconnection attempts. This method allows the user to provide any function that returns a value which is convertible into an iterator, such as an actual iterator or a Vec.

§Examples
use std::time::Duration;
use stream_reconnect::ReconnectOptions;

// With the below vector, the ReconnectStream item will try to reconnect three times,
// waiting 2 seconds between each attempt. Once all three tries are exhausted,
// it will stop attempting.
let options = ReconnectOptions::new().with_retries_generator(|| {
    vec![
        Duration::from_secs(2),
        Duration::from_secs(2),
        Duration::from_secs(2),
    ]
});
Source

pub fn with_exit_if_first_connect_fails(self, value: bool) -> Self

If this is set to true, if the initial connect method of the ReconnectStream item fails, then no further reconnects will be attempted

Source

pub fn with_on_connect_callback( self, cb: impl Fn() + 'static + Send + Sync, ) -> Self

Invoked when the ReconnectStream establishes a connection

Source

pub fn with_on_disconnect_callback( self, cb: impl Fn() + 'static + Send + Sync, ) -> Self

Invoked when the ReconnectStream loses its active connection

Source

pub fn with_on_connect_fail_callback( self, cb: impl Fn() + 'static + Send + Sync, ) -> Self

Invoked when the ReconnectStream fails a connection attempt

Trait Implementations§

Source§

impl Clone for ReconnectOptions

Source§

fn clone(&self) -> ReconnectOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.