1#![allow(clippy::unused_async_trait_impl)]
2use std::io;
3
4pub trait ServerAppConfig: Sync + Send + 'static {
5 type State: Clone;
6
7 async fn create(&self) -> io::Result<Self::State>;
8}
9
10#[derive(Copy, Clone, Default, Debug)]
11pub struct NoConfig;
12
13impl ServerAppConfig for NoConfig {
14 type State = ();
15
16 async fn create(&self) -> io::Result<()> {
17 Ok(())
18 }
19}
20
21impl<F, Cfg> ServerAppConfig for F
22where
23 F: AsyncFn() -> io::Result<Cfg> + Sync + Send + 'static,
24 Cfg: Clone,
25{
26 type State = Cfg;
27
28 async fn create(&self) -> io::Result<Cfg> {
29 (*self)().await
30 }
31}