1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use super::HttpServer;
use crate::server::{FromRequest, Req, Route, RouteImpl};
use anyhow::Error;
use derive_more::From;
use meio::prelude::{Action, Actor, Address, InteractionHandler};
use std::marker::PhantomData;

#[derive(Debug, Clone, From)]
pub struct HttpServerLink {
    address: Address<HttpServer>,
}

pub(super) struct AddRoute {
    pub route: Box<dyn Route>,
}

impl Action for AddRoute {}

impl HttpServerLink {
    pub async fn add_route<E, A>(&mut self, address: Address<A>) -> Result<(), Error>
    where
        E: FromRequest,
        A: Actor + InteractionHandler<Req<E>>,
    {
        let route = RouteImpl {
            extracted: PhantomData,
            address,
        };
        let msg = AddRoute {
            route: Box::new(route),
        };
        self.address.act(msg).await
    }
}