[−][src]Struct commune::Device
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]
T: Serialize,
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 IDdata
- 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]
T: Deserialize<'de>,
Takes the contents of the RX buffer and deserializes it to type T.
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,