Struct distant_net::client::Client
source · pub struct Client<T, U> { /* private fields */ }
Expand description
Represents a client that can be used to send requests & receive responses from a server.
Implementations§
source§impl<T, U> Client<T, U>where
T: Send + Sync + Serialize + 'static,
U: Send + Sync + DeserializeOwned + 'static,
impl<T, U> Client<T, U>where T: Send + Sync + Serialize + 'static, U: Send + Sync + DeserializeOwned + 'static,
sourcepub fn into_untyped_client(self) -> UntypedClient
pub fn into_untyped_client(self) -> UntypedClient
Consumes the client, returning an untyped variant.
sourcepub fn spawn_inmemory(
transport: FramedTransport<InmemoryTransport>,
config: ClientConfig
) -> Self
pub fn spawn_inmemory( transport: FramedTransport<InmemoryTransport>, config: ClientConfig ) -> Self
Spawns a client using the provided FramedTransport
of InmemoryTransport
and a
specific ReconnectStrategy
.
Note
This will NOT perform any handshakes or authentication procedures nor will it replay any
missing frames. This is to be used when establishing a Client
to be run internally
within a program.
source§impl Client<(), ()>
impl Client<(), ()>
sourcepub fn build() -> ClientBuilder<(), ()>
pub fn build() -> ClientBuilder<(), ()>
Creates a new ClientBuilder
.
sourcepub fn tcp<T>(
connector: impl Into<TcpConnector<T>>
) -> ClientBuilder<(), TcpConnector<T>>
pub fn tcp<T>( connector: impl Into<TcpConnector<T>> ) -> ClientBuilder<(), TcpConnector<T>>
Creates a new ClientBuilder
configured to use a TcpConnector
.
sourcepub fn local_windows_pipe(
connector: impl Into<WindowsPipeConnector>
) -> ClientBuilder<(), WindowsPipeConnector>
pub fn local_windows_pipe( connector: impl Into<WindowsPipeConnector> ) -> ClientBuilder<(), WindowsPipeConnector>
Creates a new ClientBuilder
configured to use a local WindowsPipeConnector
.
sourcepub fn windows_pipe(
connector: impl Into<WindowsPipeConnector>
) -> ClientBuilder<(), WindowsPipeConnector>
pub fn windows_pipe( connector: impl Into<WindowsPipeConnector> ) -> ClientBuilder<(), WindowsPipeConnector>
Creates a new ClientBuilder
configured to use a WindowsPipeConnector
.
source§impl<T, U> Client<T, U>
impl<T, U> Client<T, U>
sourcepub fn into_channel(self) -> Channel<T, U>
pub fn into_channel(self) -> Channel<T, U>
Convert into underlying channel.
sourcepub fn clone_channel(&self) -> Channel<T, U>
pub fn clone_channel(&self) -> Channel<T, U>
Clones the underlying channel for requests and returns the cloned instance.
sourcepub async fn wait(self) -> Result<()>
pub async fn wait(self) -> Result<()>
Waits for the client to terminate, which resolves when the receiving end of the network connection is closed (or the client is shutdown). Returns whether or not the client exited successfully or due to an error.
sourcepub fn clone_shutdown(&self) -> Box<dyn Shutdown>
pub fn clone_shutdown(&self) -> Box<dyn Shutdown>
Clones the underlying shutdown signaler for the client. This enables you to wait on the client while still having the option to shut it down from somewhere else.
sourcepub async fn shutdown(&self) -> Result<()>
pub async fn shutdown(&self) -> Result<()>
Signal for the client to shutdown its connection cleanly.
sourcepub fn will_shutdown_on_drop(&mut self) -> bool
pub fn will_shutdown_on_drop(&mut self) -> bool
Returns whether the client should fully shutdown once it is dropped. If true, this will result in all channels tied to the client no longer functioning once the client is dropped.
sourcepub fn shutdown_on_drop(&mut self, shutdown_on_drop: bool)
pub fn shutdown_on_drop(&mut self, shutdown_on_drop: bool)
Sets whether the client should fully shutdown once it is dropped. If true, this will result in all channels tied to the client no longer functioning once the client is dropped.
sourcepub fn clone_connection_watcher(&self) -> ConnectionWatcher
pub fn clone_connection_watcher(&self) -> ConnectionWatcher
Clones the underlying [ConnectionStateWatcher
] for the client.
sourcepub fn on_connection_change<F>(&self, f: F) -> JoinHandle<()>where
F: FnMut(ConnectionState) + Send + 'static,
pub fn on_connection_change<F>(&self, f: F) -> JoinHandle<()>where F: FnMut(ConnectionState) + Send + 'static,
Spawns a new task that continually monitors for connection changes and invokes the function
f
whenever a new change is detected.
sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true if client’s underlying event processing has finished/terminated.
source§impl Client<ManagerRequest, ManagerResponse>
impl Client<ManagerRequest, ManagerResponse>
sourcepub async fn launch(
&mut self,
destination: impl Into<Destination>,
options: impl Into<Map>,
handler: impl AuthHandler + Send
) -> Result<Destination>
pub async fn launch( &mut self, destination: impl Into<Destination>, options: impl Into<Map>, handler: impl AuthHandler + Send ) -> Result<Destination>
Request that the manager launches a new server at the given destination
with options
being passed for destination-specific details, returning the new destination
of the
spawned server.
The provided handler
will be used for any authentication requirements when connecting to
the remote machine to spawn the server.
sourcepub async fn connect(
&mut self,
destination: impl Into<Destination>,
options: impl Into<Map>,
handler: impl AuthHandler + Send
) -> Result<ConnectionId>
pub async fn connect( &mut self, destination: impl Into<Destination>, options: impl Into<Map>, handler: impl AuthHandler + Send ) -> Result<ConnectionId>
Request that the manager establishes a new connection at the given destination
with options
being passed for destination-specific details.
The provided handler
will be used for any authentication requirements when connecting to
the server.
sourcepub async fn open_raw_channel(
&mut self,
connection_id: ConnectionId
) -> Result<RawChannel>
pub async fn open_raw_channel( &mut self, connection_id: ConnectionId ) -> Result<RawChannel>
Establishes a channel with the server represented by the connection_id
,
returning a RawChannel
acting as the connection.
Note
Multiple calls to open a channel against the same connection will result in establishing a duplicate channel to the same server, so take care when using this method.
sourcepub async fn info(&mut self, id: ConnectionId) -> Result<ConnectionInfo>
pub async fn info(&mut self, id: ConnectionId) -> Result<ConnectionInfo>
Retrieves information about a specific connection
sourcepub async fn kill(&mut self, id: ConnectionId) -> Result<()>
pub async fn kill(&mut self, id: ConnectionId) -> Result<()>
Kills the specified connection
sourcepub async fn list(&mut self) -> Result<ConnectionList>
pub async fn list(&mut self) -> Result<ConnectionList>
Retrieves a list of active connections
Methods from Deref<Target = Channel<T, U>>§
sourcepub async fn assign_default_mailbox(
&self,
buffer: usize
) -> Result<Mailbox<Response<U>>>
pub async fn assign_default_mailbox( &self, buffer: usize ) -> Result<Mailbox<Response<U>>>
Assigns a default mailbox for any response received that does not match another mailbox.
sourcepub async fn remove_default_mailbox(&self) -> Result<()>
pub async fn remove_default_mailbox(&self) -> Result<()>
Removes the default mailbox used for unmatched responses such that any response without a matching mailbox will be dropped.
sourcepub async fn mail(
&mut self,
req: impl Into<Request<T>>
) -> Result<Mailbox<Response<U>>>
pub async fn mail( &mut self, req: impl Into<Request<T>> ) -> Result<Mailbox<Response<U>>>
Sends a request and returns a mailbox that can receive one or more responses, failing if unable to send a request or if the session’s receiving line to the remote server has already been severed
sourcepub async fn mail_timeout(
&mut self,
req: impl Into<Request<T>>,
duration: impl Into<Option<Duration>>
) -> Result<Mailbox<Response<U>>>
pub async fn mail_timeout( &mut self, req: impl Into<Request<T>>, duration: impl Into<Option<Duration>> ) -> Result<Mailbox<Response<U>>>
Sends a request and returns a mailbox, timing out after duration has passed
sourcepub async fn send(&mut self, req: impl Into<Request<T>>) -> Result<Response<U>>
pub async fn send(&mut self, req: impl Into<Request<T>>) -> Result<Response<U>>
Sends a request and waits for a response, failing if unable to send a request or if the session’s receiving line to the remote server has already been severed
sourcepub async fn send_timeout(
&mut self,
req: impl Into<Request<T>>,
duration: impl Into<Option<Duration>>
) -> Result<Response<U>>
pub async fn send_timeout( &mut self, req: impl Into<Request<T>>, duration: impl Into<Option<Duration>> ) -> Result<Response<U>>
Sends a request and waits for a response, timing out after duration has passed