ergot/interface_manager/profiles/
null.rs

1//! The Null Profile
2//!
3//! This is the simplest profile, and does not handle external connections at all.
4//!
5//! Useful for testing, or cases where only local communication is desirable.
6
7use serde::Serialize;
8
9use crate::{
10    Header, HeaderSeq,
11    interface_manager::{ConstInit, InterfaceSendError, InterfaceState, Profile, SetStateError},
12};
13
14/// The null profile
15pub struct Null {
16    _priv: (),
17}
18
19impl ConstInit for Null {
20    const INIT: Self = Self { _priv: () };
21}
22
23impl Profile for Null {
24    type InterfaceIdent = ();
25
26    fn send<T: Serialize>(&mut self, hdr: &Header, _data: &T) -> Result<(), InterfaceSendError> {
27        if hdr.dst.net_node_any() {
28            Err(InterfaceSendError::DestinationLocal)
29        } else {
30            Err(InterfaceSendError::NoRouteToDest)
31        }
32    }
33
34    fn send_raw(
35        &mut self,
36        hdr: &HeaderSeq,
37        _data: &[u8],
38        _source: Self::InterfaceIdent,
39    ) -> Result<(), InterfaceSendError> {
40        if hdr.dst.net_node_any() {
41            Err(InterfaceSendError::DestinationLocal)
42        } else {
43            Err(InterfaceSendError::NoRouteToDest)
44        }
45    }
46
47    fn send_err(
48        &mut self,
49        hdr: &Header,
50        _err: crate::ProtocolError,
51        _source: Option<Self::InterfaceIdent>,
52    ) -> Result<(), InterfaceSendError> {
53        if hdr.dst.net_node_any() {
54            Err(InterfaceSendError::DestinationLocal)
55        } else {
56            Err(InterfaceSendError::NoRouteToDest)
57        }
58    }
59
60    fn interface_state(&mut self, _ident: Self::InterfaceIdent) -> Option<InterfaceState> {
61        None
62    }
63
64    fn set_interface_state(
65        &mut self,
66        _ident: Self::InterfaceIdent,
67        _state: InterfaceState,
68    ) -> Result<(), crate::interface_manager::SetStateError> {
69        Err(SetStateError::InterfaceNotFound)
70    }
71}