Skip to main content

MaybeFuture

Trait MaybeFuture 

Source
pub trait MaybeFuture: IntoFuture + Sized {
    // Provided method
    fn wait(self) -> Self::Output { ... }
}
Expand description

Extension trait adding a blocking .wait() to every action.

Blanket-implemented for everything awaitable, so any Hidra / HidDevice method can be driven with .wait() on native targets. Not available on wasm32, where blocking the (single) thread is impossible; use .await instead.

Provided Methods§

Source

fn wait(self) -> Self::Output

Run the action to completion, blocking the current thread.

Examples found in repository?
examples/backends.rs (line 39)
37    fn product_string_of(&self, vid: u16, pid: u16) -> HidResult<Option<String>> {
38        match self {
39            Api::Native(api) => api.open(vid, pid).wait()?.get_product_string().wait(),
40            Api::Nusb(api) => api.open(vid, pid).wait()?.get_product_string().wait(),
41        }
42    }
More examples
Hide additional examples
examples/read_input.rs (line 20)
12fn main() -> hidra::HidResult<()> {
13    let mut args = env::args().skip(1);
14    let vid = u16::from_str_radix(&args.next().expect("usage: read_input <vid> <pid>"), 16)
15        .expect("vid must be hex");
16    let pid = u16::from_str_radix(&args.next().expect("usage: read_input <vid> <pid>"), 16)
17        .expect("pid must be hex");
18
19    let api = hidra::Hidra::new()?;
20    let device = api.open(vid, pid).wait()?;
21
22    println!("product: {:?}", device.get_product_string().wait()?);
23    let descriptor = device.parsed_report_descriptor().wait()?;
24    println!(
25        "report descriptor: {} top-level collection(s), max input report {} bytes, numbered ids: {}",
26        descriptor.collections.len(),
27        descriptor.max_report_size(hidra::descriptor::ReportKind::Input),
28        descriptor.uses_report_ids(),
29    );
30
31    println!("reading input reports (ctrl-c to quit)...");
32    let mut buf = [0u8; 256];
33    loop {
34        // Blocks until a report arrives; never returns 0.
35        let len = device.read(&mut buf).wait()?;
36        println!("{:02x?}", &buf[..len]);
37    }
38}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: IntoFuture> MaybeFuture for T

Available on non-WebAssembly only.