11use {
22 crate :: {
33 config:: RunOptions ,
4- state:: State ,
4+ state:: {
5+ Aggregates ,
6+ Benchmarks ,
7+ Cache ,
8+ Metrics ,
9+ } ,
510 } ,
611 anyhow:: Result ,
712 axum:: {
@@ -24,7 +29,7 @@ mod rest;
2429pub mod types;
2530mod ws;
2631
27- pub struct ApiState < S = State > {
32+ pub struct ApiState < S > {
2833 pub state : Arc < S > ,
2934 pub ws : Arc < ws:: WsState > ,
3035 pub metrics : Arc < metrics_middleware:: ApiMetrics > ,
@@ -42,12 +47,12 @@ impl<S> Clone for ApiState<S> {
4247 }
4348}
4449
45- impl ApiState < State > {
46- pub fn new (
47- state : Arc < State > ,
48- ws_whitelist : Vec < IpNet > ,
49- requester_ip_header_name : String ,
50- ) -> Self {
50+ impl < S > ApiState < S > {
51+ pub fn new ( state : Arc < S > , ws_whitelist : Vec < IpNet > , requester_ip_header_name : String ) -> Self
52+ where
53+ S : Metrics ,
54+ S : Send + Sync + ' static ,
55+ {
5156 Self {
5257 metrics : Arc :: new ( metrics_middleware:: ApiMetrics :: new ( state. clone ( ) ) ) ,
5358 ws : Arc :: new ( ws:: WsState :: new (
@@ -61,7 +66,14 @@ impl ApiState<State> {
6166}
6267
6368#[ tracing:: instrument( skip( opts, state) ) ]
64- pub async fn spawn ( opts : RunOptions , state : Arc < State > ) -> Result < ( ) > {
69+ pub async fn spawn < S > ( opts : RunOptions , state : Arc < S > ) -> Result < ( ) >
70+ where
71+ S : Aggregates ,
72+ S : Benchmarks ,
73+ S : Cache ,
74+ S : Metrics ,
75+ S : Send + Sync + ' static ,
76+ {
6577 let state = {
6678 let opts = opts. clone ( ) ;
6779 ApiState :: new (
@@ -79,7 +91,14 @@ pub async fn spawn(opts: RunOptions, state: Arc<State>) -> Result<()> {
7991/// Currently this is based on Axum due to the simplicity and strong ecosystem support for the
8092/// packages they are based on (tokio & hyper).
8193#[ tracing:: instrument( skip( opts, state) ) ]
82- pub async fn run ( opts : RunOptions , state : ApiState ) -> Result < ( ) > {
94+ pub async fn run < S > ( opts : RunOptions , state : ApiState < S > ) -> Result < ( ) >
95+ where
96+ S : Aggregates ,
97+ S : Benchmarks ,
98+ S : Cache ,
99+ S : Metrics ,
100+ S : Send + Sync + ' static ,
101+ {
83102 tracing:: info!( endpoint = %opts. rpc. listen_addr, "Starting RPC Server." ) ;
84103
85104 #[ derive( OpenApi ) ]
0 commit comments