-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.rs
38 lines (31 loc) · 1 KB
/
register.rs
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
35
36
37
38
use crate::Result;
/// trait to register a domain. Normally this should expose the domain
/// to the given port
#[async_trait::async_trait]
pub trait Registerer: Send + Sync + 'static {
// The handler is returned when a registration happens
// the point is when the handler is dropped, this must take care
// of auto removal of the registration
type Handler: Send + Sync + 'static;
async fn register(&self, domain: &str, port: u16) -> Result<Self::Handler>;
}
#[derive(Debug, Clone)]
pub struct PrintRegisterer;
#[async_trait::async_trait]
impl Registerer for PrintRegisterer {
type Handler = PrintHandler;
async fn register(&self, domain: &str, port: u16) -> Result<Self::Handler> {
log::info!("register domain '{}' -> '{}'", domain, port);
Ok(PrintHandler {
name: domain.into(),
})
}
}
pub struct PrintHandler {
name: String,
}
impl Drop for PrintHandler {
fn drop(&mut self) {
log::info!("unregister domain '{}'", self.name);
}
}