Skip to main content

gproxy_channel_api/
registration.rs

1//! Compile-time registration contract for externally linked channel crates.
2
3use std::sync::Arc;
4
5use crate::{Channel, ChannelLogin};
6
7/// One channel implementation and its optional interactive-login adapter.
8pub struct RegisteredChannel {
9    pub channel: Arc<dyn Channel>,
10    pub login: Option<Arc<dyn ChannelLogin>>,
11}
12
13impl RegisteredChannel {
14    pub fn new(channel: Arc<dyn Channel>) -> Self {
15        Self {
16            channel,
17            login: None,
18        }
19    }
20
21    pub fn with_login(channel: Arc<dyn Channel>, login: Arc<dyn ChannelLogin>) -> Self {
22        Self {
23            channel,
24            login: Some(login),
25        }
26    }
27}
28
29/// Startup constructor collected from an externally linked channel crate.
30pub type ChannelRegistration = fn() -> RegisteredChannel;
31
32/// Native compile-time registration slice.
33#[cfg(all(not(target_arch = "wasm32"), feature = "external-channels"))]
34#[linkme::distributed_slice]
35pub static CHANNEL_REGISTRATIONS: [ChannelRegistration];