Skip to main content

rs_matter_stack/
network.rs

1use rs_matter::dm::clusters::net_comm::Networks as RsNetworks;
2use rs_matter::pairing::DiscoveryCapabilities;
3use rs_matter::utils::init::{init_from_closure, Init};
4
5use crate::private::Sealed;
6
7/// User data that can be embedded in the stack network
8pub trait Embedding {
9    const INIT: Self;
10
11    fn init() -> impl Init<Self>;
12}
13
14impl Embedding for () {
15    const INIT: Self = ();
16
17    fn init() -> impl Init<Self> {
18        unsafe { init_from_closure(|_| Ok(())) }
19    }
20}
21
22/// A trait modeling a specific network type.
23/// `MatterStack` is parameterized by a network type implementing this trait.
24///
25/// The trait is sealed and has only two implementations: `Eth` and `WirelessBle`.
26pub trait Network: Sealed {
27    const INIT: Self;
28
29    /// Optional additional state embedded in the network state
30    type Embedding<'a>: Embedding
31    where
32        Self: 'a;
33
34    /// The `rs-matter` networks store type owned by the stack's
35    /// `InteractionModelState` for this network kind.
36    ///
37    /// For Ethernet (and other transports where the Matter stack does not manage
38    /// network credentials) this is a no-op store; for the wireless (BLE+Wifi/Thread)
39    /// network it is a `WirelessNetworks` store.
40    type Networks: RsNetworks;
41
42    /// A const initializer for the `rs-matter` networks store (used by the
43    /// `const` `MatterStack::new` constructor).
44    const NETWORKS: Self::Networks;
45
46    /// Return an in-place initializer for the network type.
47    fn init() -> impl Init<Self>;
48
49    /// Return an in-place initializer for the `rs-matter` networks store.
50    fn init_networks() -> impl Init<Self::Networks>;
51
52    /// Return the discovery capabilities of this network when commissioning the device.
53    fn discovery_capabilities(&self) -> DiscoveryCapabilities;
54
55    /// Return a reference to the embedded user data.
56    fn embedding(&self) -> &Self::Embedding<'_>;
57}