capnproto-rust
capnproto-rust copied to clipboard
Is there a way for a server to accept multiple type of clients?
Hi there,
I have two interfaces:
interface Margin {
struct Item {
symbolId @0 : Int32;
price @1 : Float64;
amount @2 : Int32
}
get @0 () -> (margin: List(Item));
}
interface StockWatchList {
struct Stock {
symbolId @0 : Int32;
exId @1 : Int16;
}
struct Delay {
symbolId @0 : Int32;
exId @1 : Int16;
spiderDelay @2 : Int32;
source @3 : Int16;
}
getWatchList @0 () -> (stock_list: List(Stock));
insertDelay @1(delay: Delay);
}
I'm trying to implement a server accepting either a margin::Client or a stock_watch_list::Client, but when constructing the rpc system, I have to specify the type of the client:
struct RpcClient;
impl margin::Server for RpcClient {...}
impl stock_watch_list::Server for RpcClient {...}
let client: margin::Client = capnp_rpc::new_client(RpcClient);
// or
// let client: stock_watch_list::Client = capnp_rpc::new_client(RpcClient);
let rpc_system = RpcSystem::new(network, Some(client.clone().client));
Is there a way to enable this system to accept multiple types of clients?
Thanks a lot.
You could define a new interface that gives access to both of your existing interfaces:
interface Meta {
getMargin @0 () -> Margin;
getStockWatchList @1 () -> StockWatchList;
}
Another thing that might work is to define an interface that extends both of your existing interfaces:
interface Meta extends (Margin, StockWatchList) {}