SetTarget

Trait SetTarget 

Source
pub trait SetTarget<C> {
    // Required methods
    fn add_ref(&self) -> Box<dyn SetTarget<C>>;
    fn set_target(&self, target: C);
}
Expand description

Trait implemented by the reconnecting client to set new connection out-of-band.

When using auto_reconnect or lazy_auto_reconnect it is not always optimal to wait for a call to fail with Disconnected before replacing the client that is wrapped with a new fresh one.

Sometimes we know by other means that a client has gone away. It could be that we have clients that automatically sends us a new capability when it reconnects to us.

For these situations you can use the implementation of this trait that you get from auto_reconnect or lazy_auto_reconnect to manually set the target of the wrapped client.

§Example

// The reconnecting client that automatically calls connect
let (foo_client, set_target) = auto_reconnect(|| {
    Ok(new_future_client(connect()))
})?;

// do work with foo_client
...

// We become aware that the client has gone so reconnect manually
set_target.set_target(new_future_client(connect()));

// do more work with foo_client
...

Required Methods§

Source

fn add_ref(&self) -> Box<dyn SetTarget<C>>

Adds a new reference to this implementation of SetTarget.

This is mostly to get around that Clone requires Sized and so you need this trick to get a copy of the Box<dyn SetTarget<C>> you got from making the reconnecting client.

Source

fn set_target(&self, target: C)

Sets the target client of the reconnecting client that this trait implementation is for.

Trait Implementations§

Source§

impl<C> Clone for Box<dyn SetTarget<C>>

Source§

fn clone(&self) -> Self

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

Implementors§