Skip to main content

tuwunel_router/
mod.rs

1#![recursion_limit = "256"]
2
3mod handle;
4mod layers;
5mod request;
6mod router;
7mod run;
8mod serve;
9
10use std::{panic::AssertUnwindSafe, pin::Pin, sync::Arc};
11
12use futures::{FutureExt, TryFutureExt};
13use log as _;
14use tuwunel_core::{Error, Result, Server};
15use tuwunel_service::Services;
16
17tuwunel_core::mod_ctor! {}
18tuwunel_core::mod_dtor! {}
19tuwunel_core::rustc_flags_capture! {}
20
21#[unsafe(no_mangle)]
22pub extern "Rust" fn start(
23	server: &Arc<Server>,
24) -> Pin<Box<dyn Future<Output = Result<Arc<Services>>> + Send>> {
25	AssertUnwindSafe(run::start(server.clone()))
26		.catch_unwind()
27		.map_err(Error::from_panic)
28		.unwrap_or_else(Err)
29		.boxed() // type-erasure boundary
30}
31
32#[unsafe(no_mangle)]
33pub extern "Rust" fn stop(
34	services: Arc<Services>,
35) -> Pin<Box<dyn Future<Output = Result> + Send>> {
36	AssertUnwindSafe(run::stop(services))
37		.catch_unwind()
38		.map_err(Error::from_panic)
39		.unwrap_or_else(Err)
40		.boxed() // type-erasure boundary
41}
42
43#[unsafe(no_mangle)]
44pub extern "Rust" fn run(
45	services: &Arc<Services>,
46) -> Pin<Box<dyn Future<Output = Result> + Send>> {
47	AssertUnwindSafe(run::run(services.clone()))
48		.catch_unwind()
49		.map_err(Error::from_panic)
50		.unwrap_or_else(Err)
51		.boxed() // type-erasure boundary
52}