bluetooth_mesh 0.1.4

Cross-platform, full Bluetooth Mesh stack implemented in Rust. Following the Bluetooth Mesh Spec Core v1.0 by SIG. Designed to work with any almost any BLE radio (uses https://github.com/AndrewGi/btle/ for platform dependent Bluetooth drivers). While a stack is provided by the library, all the primatives and objects needed to customize and create your own stack are provided. See https://github.com/AndrewGi/BluetoothMeshRust for more.
Documentation
//! Network Input/Output Interface and Filter.
use crate::bearer::{BearerError, IncomingEncryptedNetworkPDU, OutgoingEncryptedNetworkPDU};
use alloc::vec::Vec;

pub trait InterfaceSink {
    fn consume_pdu(&mut self, pdu: &IncomingEncryptedNetworkPDU);
}
pub trait InputInterface<Sink: InterfaceSink> {
    fn take_sink(&mut self, sink: Sink);
}

pub struct InputInterfaces<Sink: InterfaceSink + Clone> {
    sink: Sink,
}
impl<Sink: InterfaceSink + Clone> InputInterfaces<Sink> {
    pub fn new(sink: Sink) -> Self {
        Self { sink }
    }
    pub fn add(&self, interface: &mut dyn InputInterface<Sink>) {
        interface.take_sink(self.sink.clone())
    }
}
pub trait OutputInterface {
    fn send_pdu(&mut self, pdu: &OutgoingEncryptedNetworkPDU) -> Result<(), BearerError>;
}
#[derive(Default)]
pub struct OutputInterfaces<'a> {
    interfaces: Vec<&'a mut dyn OutputInterface>,
}
impl<'a> OutputInterfaces<'a> {
    pub fn new() -> Self {
        Self::default()
    }
    pub fn add_interface<'b: 'a>(&mut self, interface: &'b mut dyn OutputInterface) {
        self.interfaces.push(interface)
    }
    pub fn send_pdu(&mut self, pdu: &OutgoingEncryptedNetworkPDU) -> Result<(), BearerError> {
        for interface in self.interfaces.iter_mut() {
            (*interface).send_pdu(pdu)?
        }
        Ok(())
    }
}