Struct selectme::StaticSelect
source · pub struct StaticSelect<Bits, S, B, O> { /* private fields */ }
Expand description
The implementation used by the select! macro internally
and returned by the inline! macro when the static;
option is enabled.
See the select! and inline! macros for documentation on syntax and use.
Examples
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;
use pin_project::pin_project;
use selectme::{Random, StaticSelect};
use tokio::time::{self, Sleep};
#[pin_project]
struct MyFuture {
#[pin]
select: StaticSelect<u8, (Sleep, Sleep), Random, Option<u32>>,
}
impl Future for MyFuture {
type Output = Option<u32>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
this.select.poll_next(cx)
}
}
let s1 = time::sleep(Duration::from_millis(100));
let s2 = time::sleep(Duration::from_millis(200));
let my_future = MyFuture {
select: selectme::inline! {
static;
() = s1 => Some(1),
_ = s2 => Some(2),
else => None,
}
};
assert_eq!(my_future.await, Some(1));
Implementations§
source§impl<Bits, S, B, O> StaticSelect<Bits, S, B, O>where
Bits: Number,
B: Bias<Bits>,
impl<Bits, S, B, O> StaticSelect<Bits, S, B, O>where Bits: Number, B: Bias<Bits>,
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! {
static;
() = 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§
source§impl<Bits, S, B, O> Debug for StaticSelect<Bits, S, B, O>where
Bits: Number,
B: Debug,
S: Debug,
impl<Bits, S, B, O> Debug for StaticSelect<Bits, S, B, O>where Bits: Number, B: Debug, S: Debug,
source§impl<Bits, S, B, O> Future for StaticSelect<Bits, S, B, O>where
Bits: Number,
B: Bias<Bits>,
impl<Bits, S, B, O> Future for StaticSelect<Bits, S, B, O>where Bits: Number, B: Bias<Bits>,
Auto Trait Implementations§
impl<Bits, S, B, O> RefUnwindSafe for StaticSelect<Bits, S, B, O>where B: RefUnwindSafe, Bits: RefUnwindSafe, S: RefUnwindSafe,
impl<Bits, S, B, O> Send for StaticSelect<Bits, S, B, O>where B: Send, Bits: Send, S: Send,
impl<Bits, S, B, O> Sync for StaticSelect<Bits, S, B, O>where B: Sync, Bits: Sync, S: Sync,
impl<Bits, S, B, O> Unpin for StaticSelect<Bits, S, B, O>where B: Unpin, Bits: Unpin, S: Unpin,
impl<Bits, S, B, O> UnwindSafe for StaticSelect<Bits, S, B, O>where B: UnwindSafe, Bits: UnwindSafe, S: 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