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