Trait radio::nonblocking::AsyncReceive

source ·
pub trait AsyncReceive<'a, I, E> {
    type Output: Future<Output = Result<(usize, I), AsyncError<E>>>;

    // Required method
    fn async_receive(
        &'a mut self,
        buff: &'a mut [u8],
        rx_options: AsyncOptions
    ) -> Result<Self::Output, E>;
}
Expand description

Async transmit function implemented over radio::Transmit and radio::Power using the provided AsyncOptions

extern crate async_std;
use async_std::task;

use radio::nonblocking::{AsyncReceive, AsyncOptions};

let data = [0xaa, 0xbb];
let info = BasicInfo::new(-81, 0);


// Setup buffer and receive info
let mut buff = [0u8; 128];
let mut i = BasicInfo::new(0, 0);

let (n, i) = task::block_on(async {
    // Receive using a future
    radio.async_receive(&mut buff, AsyncOptions::default())?.await
})?;

assert_eq!(n, data.len());
assert_eq!(&buff[..data.len()], &data);


Ok::<(), anyhow::Error>(())

AsyncReceive trait support futures-based polling on receive

Required Associated Types§

source

type Output: Future<Output = Result<(usize, I), AsyncError<E>>>

Required Methods§

source

fn async_receive( &'a mut self, buff: &'a mut [u8], rx_options: AsyncOptions ) -> Result<Self::Output, E>

Implementors§

source§

impl<'a, T, I, E> AsyncReceive<'a, I, E> for T
where T: Receive<Error = E, Info = I> + 'a, I: ReceiveInfo + Unpin + 'a, E: Debug + Unpin,

Generic implementation of AsyncReceive for all Receive capable radio devices

§

type Output = ReceiveFuture<'a, T, I, E>