Skip to main content

vox_core/
into_conduit.rs

1use vox_types::{Link, MessageFamily, MsgFamily};
2
3use crate::BareConduit;
4
5/// Converts a value into a [`vox_types::Conduit`].
6///
7/// Implemented for:
8/// - Any [`Link`] → wraps it in a [`BareConduit`] automatically
9/// - [`BareConduit`] → identity (pass-through)
10/// - [`crate::StableConduit`] → identity (pass-through)
11///
12/// This allows [`crate::Session`] connection handling methods
13/// to accept raw links directly, without requiring callers to wrap them in
14/// `BareConduit::new()` manually.
15pub trait IntoConduit {
16    /// The conduit type produced by this conversion.
17    type Conduit;
18
19    /// Convert into a conduit.
20    fn into_conduit(self) -> Self::Conduit;
21}
22
23/// Any [`Link`] becomes a [`BareConduit`] over [`MessageFamily`].
24impl<L: Link> IntoConduit for L {
25    type Conduit = BareConduit<MessageFamily, L>;
26
27    fn into_conduit(self) -> Self::Conduit {
28        BareConduit::new(self)
29    }
30}
31
32/// [`BareConduit`] passes through unchanged.
33impl<F: MsgFamily, L: Link> IntoConduit for BareConduit<F, L> {
34    type Conduit = BareConduit<F, L>;
35
36    fn into_conduit(self) -> Self::Conduit {
37        self
38    }
39}
40
41/// [`crate::StableConduit`] passes through unchanged.
42#[cfg(not(target_arch = "wasm32"))]
43impl<F: MsgFamily, LS: crate::LinkSource> IntoConduit for crate::StableConduit<F, LS> {
44    type Conduit = crate::StableConduit<F, LS>;
45
46    fn into_conduit(self) -> Self::Conduit {
47        self
48    }
49}