Skip to main content

Connector

Trait Connector 

Source
pub trait Connector: Send + Sync {
    type Caps: Copy + Send + Sync + 'static;

    // Required methods
    fn caps(&self) -> Self::Caps;
    fn shutdown<'async_trait>(
        self,
        mode: ShutdownMode,
    ) -> Pin<Box<dyn Future<Output = ShutdownReport> + Send + 'async_trait>>
       where Self: Sized + 'async_trait;
}
Expand description

What every connector offers besides its capabilities: it says what it can do, and it stops.

Code that is generic over a connector can ask for the capabilities without knowing the broker, and shut any connector down the same way. A market data connector has MarketDataCaps, a user data connector has UserDataCaps. The two methods are also inherent methods of each connector, so code that names the type needs no trait in scope.

§Examples

use brokapi_bcs::limits::default_limits;
use brokapi_bcs::{MarketDataConfig, MarketDataConnector};
use brokapi_core::{Connector, MarketDataCaps, ShutdownMode};
use brokapi_runtime::BrokerLimiter;

/// Works with the connector of any broker.
async fn depth_of<C: Connector<Caps = MarketDataCaps>>(c: C) -> u32 {
    let depth = c.caps().max_order_book_depth;
    c.shutdown(ShutdownMode::Immediate).await;
    depth
}

let (events_tx, _events) = tokio::sync::mpsc::channel(16);
let limiter = BrokerLimiter::new(&default_limits());
let md = MarketDataConnector::start(MarketDataConfig::new(cfg, "bcs-md"), limiter, events_tx).await?;
assert!(depth_of(md).await > 0);

Required Associated Types§

Source

type Caps: Copy + Send + Sync + 'static

The type that describes what this connector can do.

Required Methods§

Source

fn caps(&self) -> Self::Caps

What this connector can do. Read it before you use a feature that not every broker has.

Source

fn shutdown<'async_trait>( self, mode: ShutdownMode, ) -> Pin<Box<dyn Future<Output = ShutdownReport> + Send + 'async_trait>>
where Self: Sized + 'async_trait,

Stops the connector: closes its streams, gives up commands that have no answer yet (they become Error::Unknown, see ShutdownReport) and ends its tasks. Takes the connector by value, so it cannot be used afterwards.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§