use serde::Serialize;
use crate::{
Header, HeaderSeq,
interface_manager::{ConstInit, InterfaceSendError, InterfaceState, Profile, SetStateError},
};
pub struct Null {
_priv: (),
}
impl ConstInit for Null {
const INIT: Self = Self { _priv: () };
}
impl Profile for Null {
type InterfaceIdent = ();
fn send<T: Serialize>(&mut self, hdr: &Header, _data: &T) -> Result<(), InterfaceSendError> {
if hdr.dst.net_node_any() {
Err(InterfaceSendError::DestinationLocal)
} else {
Err(InterfaceSendError::NoRouteToDest)
}
}
fn send_raw(
&mut self,
hdr: &HeaderSeq,
_data: &[u8],
_source: Self::InterfaceIdent,
) -> Result<(), InterfaceSendError> {
if hdr.dst.net_node_any() {
Err(InterfaceSendError::DestinationLocal)
} else {
Err(InterfaceSendError::NoRouteToDest)
}
}
fn send_err(
&mut self,
hdr: &Header,
_err: crate::ProtocolError,
_source: Option<Self::InterfaceIdent>,
) -> Result<(), InterfaceSendError> {
if hdr.dst.net_node_any() {
Err(InterfaceSendError::DestinationLocal)
} else {
Err(InterfaceSendError::NoRouteToDest)
}
}
fn interface_state(&mut self, _ident: Self::InterfaceIdent) -> Option<InterfaceState> {
None
}
fn set_interface_state(
&mut self,
_ident: Self::InterfaceIdent,
_state: InterfaceState,
) -> Result<(), crate::interface_manager::SetStateError> {
Err(SetStateError::InterfaceNotFound)
}
}