maviola/core/marker/node.rs
1//! Markers for MAVLink [`Node`](crate::io::Node).
2
3use std::fmt::Debug;
4
5use crate::core::utils::Sealed;
6use crate::protocol::{ComponentId, DeviceId, Endpoint, MaybeVersioned, SystemId, Unset};
7
8/// <sup>🔒</sup>
9/// All kinds of nodes are falling under this trait.
10///
11/// 🔒 This trait is sealed 🔒
12///
13/// Variants:
14///
15/// * [`Proxy`]
16/// * [`Edge`]
17pub trait NodeKind: Clone + Debug + Sync + Send + Sealed {}
18
19/// Variant of a node that proxies existing messages.
20///
21/// This node can't produce messages and can be used only as a proxy with an optional message
22/// signing capability.
23#[derive(Clone, Copy, Debug)]
24pub struct Proxy;
25impl Sealed for Proxy {}
26impl NodeKind for Proxy {}
27
28/// Variant of a node with `system_id` and `component_id` being defined.
29///
30/// This node can produce messages.
31#[derive(Clone, Debug)]
32pub struct Edge<V: MaybeVersioned> {
33 pub(crate) device_id: DeviceId,
34 pub(crate) endpoint: Endpoint<V>,
35}
36impl<V: MaybeVersioned> Sealed for Edge<V> {}
37impl<V: MaybeVersioned> NodeKind for Edge<V> {}
38impl<V: MaybeVersioned> Edge<V> {
39 /// <sup>â›”</sup>
40 /// Creates a new edge configuration from the provided endpoint.
41 pub(crate) fn new(endpoint: Endpoint<V>) -> Self {
42 let device_id = DeviceId::new(endpoint.id());
43 Self {
44 endpoint,
45 device_id,
46 }
47 }
48}
49
50/// <sup>🔒</sup>
51/// Variant of a node configuration which may or may not have a connection config.
52///
53/// 🔒 This trait is sealed 🔒
54pub trait MaybeConnConf: Debug + Send + Sealed {}
55
56impl MaybeConnConf for Unset {}
57
58/// <sup>🔒</sup>
59/// Variant of a node configuration which has a connection config.
60///
61/// 🔒 This trait is sealed 🔒
62pub trait HasConnConf: MaybeConnConf {
63 /// Returns `true` if it makes sense to restart the node after connection failure.
64 ///
65 /// A blanket implementation always returns `false`.
66 fn is_repairable(&self) -> bool {
67 false
68 }
69}
70
71/// <sup>🔒</sup>
72/// Marker trait for an entity with or without MAVLink system `ID`.
73///
74/// 🔒 This trait is sealed 🔒
75pub trait MaybeSystemId: Clone + Copy + Debug + Sync + Send + Sealed {}
76
77impl MaybeSystemId for Unset {}
78
79/// Marker for an entity with a defined MAVLink system `ID`.
80#[derive(Copy, Clone, Debug)]
81pub struct HasSystemId(pub SystemId);
82impl Sealed for HasSystemId {}
83impl MaybeSystemId for HasSystemId {}
84
85/// <sup>🔒</sup>
86/// Marker trait for an entity with or without MAVLink component `ID`.
87///
88/// 🔒 This trait is sealed 🔒
89pub trait MaybeComponentId: Clone + Debug + Sync + Send + Sealed {}
90
91impl MaybeComponentId for Unset {}
92
93/// Marker for an entity with a defined MAVLink component `ID`.
94#[derive(Copy, Clone, Debug)]
95pub struct HasComponentId(pub ComponentId);
96impl Sealed for HasComponentId {}
97impl MaybeComponentId for HasComponentId {}