Struct rustdtp::ClientEventCallbacks
source · pub struct ClientEventCallbacks<R>where
R: DeserializeOwned + Send + 'static,{ /* private fields */ }Expand description
Configuration for a client’s event callbacks.
§Events
There are two events for which callbacks can be registered:
receivedisconnect
Both callbacks are optional, and can be registered for any combination of these events. Note that each callback must be provided as a function or closure returning a thread-safe future. The future will be awaited by the runtime.
§Example
let client = Client::builder()
.sending::<String>()
.receiving::<usize>()
.with_event_callbacks(
ClientEventCallbacks::new()
.on_receive(move |data| async move {
// some async operation...
println!("Received data from server: {}", data);
})
.on_disconnect(move || async move {
// some async operation...
println!("Disconnected from server");
})
)
.connect(("127.0.0.1", 29275))
.await
.unwrap();Implementations§
source§impl<R> ClientEventCallbacks<R>where
R: DeserializeOwned + Send + 'static,
impl<R> ClientEventCallbacks<R>where
R: DeserializeOwned + Send + 'static,
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new client event callbacks configuration with all callbacks empty.
sourcepub fn on_receive<C, F>(self, callback: C) -> Self
pub fn on_receive<C, F>(self, callback: C) -> Self
Registers a callback on the receive event.
Trait Implementations§
source§impl<R> Default for ClientEventCallbacks<R>where
R: DeserializeOwned + Send + 'static,
impl<R> Default for ClientEventCallbacks<R>where
R: DeserializeOwned + Send + 'static,
Auto Trait Implementations§
impl<R> !RefUnwindSafe for ClientEventCallbacks<R>
impl<R> Send for ClientEventCallbacks<R>
impl<R> !Sync for ClientEventCallbacks<R>
impl<R> Unpin for ClientEventCallbacks<R>
impl<R> !UnwindSafe for ClientEventCallbacks<R>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more