capybara_core/
builtin.rs

1use tokio::sync::OnceCell;
2
3static ONCE: OnceCell<()> = OnceCell::const_new();
4
5pub async fn setup() {
6    ONCE.get_or_init(|| async {
7        register_stream_pipeline().await;
8        register_http_pipeline().await;
9    })
10    .await;
11}
12
13#[inline(always)]
14async fn register_http_pipeline() {
15    use crate::pipeline::http::register;
16
17    {
18        use crate::pipeline::http::NoopHttpPipelineFactory as Factory;
19        let name = "capybara.pipelines.http.noop";
20        match register(name, |c| Factory::try_from(c)).await {
21            Ok(()) => info!("register '{}' ok", name),
22            Err(e) => error!("register '{}' occurs an error: {}", name, e),
23        }
24    }
25
26    {
27        use crate::pipeline::http::HttpPipelineRouterFactory as Factory;
28        let name = "capybara.pipelines.http.router";
29        match register(name, |c| Factory::try_from(c)).await {
30            Ok(()) => info!("register '{}' ok", name),
31            Err(e) => error!("register '{}' occurs an error: {}", name, e),
32        }
33    }
34
35    {
36        use crate::pipeline::http::LuaHttpPipelineFactory as Factory;
37        let name = "capybara.pipelines.http.lua";
38        match register(name, |c| Factory::try_from(c)).await {
39            Ok(()) => info!("register '{}' ok", name),
40            Err(e) => error!("register '{}' occurs an error: {}", name, e),
41        }
42    }
43}
44
45#[inline(always)]
46async fn register_stream_pipeline() {
47    use crate::pipeline::stream::register;
48
49    {
50        use crate::pipeline::stream::RouteStreamPipelineFactory as Factory;
51        let name = "capybara.pipelines.stream.router";
52        match register(name, |c| Factory::try_from(c)).await {
53            Ok(()) => info!("register '{}' ok", name),
54            Err(e) => error!("register '{}' occurs an error: {}", name, e),
55        }
56    }
57}