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>
impl<Bits, S, B, T, O> Select<Bits, S, B, T>
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> Freeze for Select<Bits, S, B, T>
impl<Bits, S, B, T> RefUnwindSafe for Select<Bits, S, B, T>
impl<Bits, S, B, T> Send for Select<Bits, S, B, T>
impl<Bits, S, B, T> Sync for Select<Bits, S, B, T>
impl<Bits, S, B, T> Unpin for Select<Bits, S, B, T>
impl<Bits, S, B, T> UnwindSafe for Select<Bits, S, B, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§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