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
use crate::address::UnicastAddress;
use crate::mesh::ElementIndex;
use crate::stack::model::Model;
use crate::stack::Stack;
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::convert::TryInto;

pub struct Element {
    address: UnicastAddress,
    models: Vec<Box<dyn Model>>,
}

pub struct ElementRef<S: Stack, Storage: Borrow<S>> {
    _marker: core::marker::PhantomData<S>,
    stack: Storage,
    element_index: ElementIndex,
}
impl<S: Stack, Storage: Borrow<S>> ElementRef<S, Storage> {
    pub fn new(stack: Storage, element_index: ElementIndex) -> Self {
        let count = stack.borrow().element_count();
        assert!(
            element_index.0 < count.0,
            "out of bounds element_index `{}` >= `{}`",
            element_index.0,
            count.0
        );
        ElementRef {
            _marker: core::marker::PhantomData,
            stack,
            element_index,
        }
    }
    pub fn stack(&self) -> &S {
        self.stack.borrow()
    }
    pub fn element_index(&self) -> ElementIndex {
        self.element_index
    }
    pub fn element_address(&self) -> UnicastAddress {
        (u16::from(self.stack().primary_address()) + u16::from(self.element_index.0))
            .try_into()
            .expect("invalid stack unicast address range")
    }
}