[][src]Struct commune::Device

pub struct Device {
    pub id: u16,
    pub rx: ArrayVec<[Frame; 64]>,
    pub tx: ArrayVec<[Frame; 64]>,
    pub scratch: [u8; 1536],
}

Represents a single transceiver

Fields

id: u16

The ID of this device

rx: ArrayVec<[Frame; 64]>tx: ArrayVec<[Frame; 64]>scratch: [u8; 1536]

Scratch buffer shared between RX and TX for easier mutations.

Implementations

impl Device[src]

pub fn new(id: u16) -> Self[src]

pub fn serialize<T>(&mut self, rx_id: u16, data: &T) -> Result<(), Error> where
    T: Serialize
[src]

Serialize data to the TX buffer via CBOR in preperation for sending across a radio or wire. This overwrites anything currently in the TX buffer without warning.

Arguments

  • rx_id - The intended receiving ID
  • data - Arbitrary data to serialize

Examples

let mut device = Device::new(1);

// Serialize the number 69 to our TX buffer, targeting another device with the ID of 0.
device.serialize(0, &69);

// We can also serialize anything implementing serde's Serialize trait.
#[derive(Serialize)]
pub struct MyData<'a> {
    name: &'a str,
    age: usize,
}

// Serialize this data TX buffer, targeting another device with the ID of 0. Our receiving device
// will need to know beforehand the data structure.
let data = MyData { name: &"Karl", age: 32 };
device.serialize(0, &data);

pub fn deserialize<'de, T>(&'de mut self) -> Result<T, Error> where
    T: Deserialize<'de>, 
[src]

Takes the contents of the RX buffer and deserializes it to type T.

Auto Trait Implementations

impl Send for Device

impl Sync for Device

impl Unpin for Device

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.