pub struct Select<Bits, S, B, T> { /* private fields */ }
Expand description
This is the type produced by the inline! macro unless the
static;
option is enabled.
Note that second type parameter T
in the Select type cannot be named. If
you want to embed a selection inside of another type have a look at
StaticSelect.
See the select! and inline! macros for documentation on syntax and use.
Examples
use std::time::Duration;
use selectme::{Random, Select};
use tokio::time;
let s1 = time::sleep(Duration::from_millis(100));
let s2 = time::sleep(Duration::from_millis(200));
let mut inlined_var = false;
let output: Select<u8, _, Random, _> = selectme::inline! {
() = s1 => {
inlined_var = true;
Some(1)
}
_ = s2 => Some(2),
else => None,
};
tokio::pin!(output);
while let Some(output) = output.as_mut().next().await {
dbg!(output);
}
dbg!(inlined_var);
Implementations§
source§impl<Bits, S, B, T, O> Select<Bits, S, B, T>where
Bits: Number,
B: Bias<Bits>,
T: FnMut(&mut Context<'_>, Pin<&mut S>, &mut Set<Bits>, u32) -> Poll<O>,
impl<Bits, S, B, T, O> Select<Bits, S, B, T>where Bits: Number, B: Bias<Bits>, T: FnMut(&mut Context<'_>, Pin<&mut S>, &mut Set<Bits>, u32) -> Poll<O>,
sourcepub async fn next(self: Pin<&mut Self>) -> O
pub async fn next(self: Pin<&mut Self>) -> O
Get the next element from this select when pinned.
Examples
use std::time::Duration;
use tokio::time;
#[selectme::main]
pub(crate) async fn main() {
let s1 = time::sleep(Duration::from_millis(100));
let s2 = time::sleep(Duration::from_millis(200));
let output = selectme::inline! {
() = s1 => Some(1),
_ = s2 => Some(2),
else => None,
};
tokio::pin!(output);
let mut values = Vec::new();
while let Some(output) = output.as_mut().next().await {
values.push(output);
}
assert_eq!(values, &[1, 2]);
}
Trait Implementations§
Auto Trait Implementations§
impl<Bits, S, B, T> RefUnwindSafe for Select<Bits, S, B, T>where B: RefUnwindSafe, Bits: RefUnwindSafe, S: RefUnwindSafe, T: RefUnwindSafe,
impl<Bits, S, B, T> Send for Select<Bits, S, B, T>where B: Send, Bits: Send, S: Send, T: Send,
impl<Bits, S, B, T> Sync for Select<Bits, S, B, T>where B: Sync, Bits: Sync, S: Sync, T: Sync,
impl<Bits, S, B, T> Unpin for Select<Bits, S, B, T>where B: Unpin, Bits: Unpin, S: Unpin, T: Unpin,
impl<Bits, S, B, T> UnwindSafe for Select<Bits, S, B, T>where B: UnwindSafe, Bits: UnwindSafe, S: UnwindSafe, T: UnwindSafe,
Blanket Implementations§
source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere F: Future,
§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more