Trait Client

Source
pub trait Client {
    type Error: Debug;

    // Required methods
    fn send_request<'life0, 'life1, 'life2, 'async_trait, P, R>(
        &'life0 self,
        method: &'life1 str,
        params: &'life2 P,
    ) -> Pin<Box<dyn Future<Output = Result<R, Self::Error>> + Send + 'async_trait>>
       where P: Serialize + Debug + Send + Sync + 'async_trait,
             R: for<'de> Deserialize<'de> + Debug + Send + Sync + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn connect_stream<'life0, 'async_trait, T>(
        &'life0 self,
        id: SubscriptionId,
    ) -> Pin<Box<dyn Future<Output = BoxStream<'static, T>> + Send + 'async_trait>>
       where T: for<'de> Deserialize<'de> + Debug + Send + Sync + 'async_trait + Unpin + 'static,
             Self: 'async_trait,
             'life0: 'async_trait;
    fn disconnect_stream<'life0, 'async_trait>(
        &'life0 self,
        id: SubscriptionId,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn close<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

This trait must be implemented by the client’s transport. It is responsible to send the request and return the server’s response.

§TODO

  • Support sending notifications (i.e. don’t set the request ID and always a Result<(), Self::Error>.

Required Associated Types§

Source

type Error: Debug

Error type that this client returns.

Required Methods§

Source

fn send_request<'life0, 'life1, 'life2, 'async_trait, P, R>( &'life0 self, method: &'life1 str, params: &'life2 P, ) -> Pin<Box<dyn Future<Output = Result<R, Self::Error>> + Send + 'async_trait>>
where P: Serialize + Debug + Send + Sync + 'async_trait, R: for<'de> Deserialize<'de> + Debug + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Sends a JSON-HTTP request

§Arguments
  • method: The name of the method to call.
  • params: The request parameters. This can be anything that implements serde::ser::Serialize, but should serialize to a struct containing the named method arguments.
§Returns

Returns either the result that was responded with by the server, or an error. The error can be either a client-side error (e.g. a network error), or an error object sent by the server.

Source

fn connect_stream<'life0, 'async_trait, T>( &'life0 self, id: SubscriptionId, ) -> Pin<Box<dyn Future<Output = BoxStream<'static, T>> + Send + 'async_trait>>
where T: for<'de> Deserialize<'de> + Debug + Send + Sync + 'async_trait + Unpin + 'static, Self: 'async_trait, 'life0: 'async_trait,

If the client supports streams (i.e. receiving notifications), this should return a stream for the specific subscription ID.

§Arguments
  • id: The subscription ID
§Returns

Returns a stream of items of type T that are received as notifications with the specific subscription ID.

§Panics

If the client doesn’t support receiving notifications, this method is allowed to panic.

Source

fn disconnect_stream<'life0, 'async_trait>( &'life0 self, id: SubscriptionId, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

If the client supports streams (i.e. receiving notifications) and there is a matching subscription ID, this should close the corresponding stream.

§Arguments
  • id: The subscription ID
§Returns

Returns a result on whether or not the client was able to unsubscribe from the stream.

§Panics

If the client doesn’t support receiving notifications, this method is allowed to panic.

Source

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Closes the client connection

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§