Skip to main content

ClientFacts

Trait ClientFacts 

Source
pub trait ClientFacts:
    Send
    + Sync
    + Sized
    + 'static {
    type Codec: Codec;
    type Task: ClientTask;

    // Required methods
    fn get_config(&self) -> &ClientConfig;
    fn new_logger(&self) -> Arc<LogFilter>;

    // Provided methods
    fn error_handle(&self, task: Self::Task) { ... }
    fn get_client_id(&self) -> u64 { ... }
    fn get_timestamp(&self) -> u64 { ... }
}
Expand description

A trait implemented by the user for the client-side, to define the customizable plugin.

Required Associated Types§

Source

type Codec: Codec

Define the codec to serialization and deserialization

Refers to Codec

Source

type Task: ClientTask

Define the RPC task from client-side

Either one ClientTask or an enum of multiple ClientTask. If you have multiple task type, recommend to use the enum_dispatch crate.

You can use macro client_task_enum and client_task on task type

Required Methods§

Source

fn get_config(&self) -> &ClientConfig

You should keep ClientConfig inside, get_config() will return the reference.

Source

fn new_logger(&self) -> Arc<LogFilter>

Construct a captains_log::filter::Filter to oganize log of a client

TODO: Fix the logger interface

Provided Methods§

Source

fn error_handle(&self, task: Self::Task)

How to deal with error

The FailoverPool will overwrite this to implement retry logic

Source

fn get_client_id(&self) -> u64

You can overwrite this to assign a client_id

Source

fn get_timestamp(&self) -> u64

NOTE: you may overwrite this to use coarstime or quanta

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§