Struct selectme::Select

source ·
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>,

source

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]);
}
source

pub fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<O>

Poll for the next branch to resolve in this Select.

Trait Implementations§

source§

impl<Bits, S, B, O> Debug for Select<Bits, S, B, O>where Bits: Number, B: Debug, S: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Bits, S, B, T, O> Future for Select<Bits, S, B, T>where Bits: Number, B: Bias<Bits>, T: FnMut(&mut Context<'_>, Pin<&mut S>, &mut Set<Bits>, u32) -> Poll<O>,

§

type Output = O

The type of value produced on completion.
source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

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<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<F> IntoFuture for Fwhere F: Future,

§

type Output = <F as Future>::Output

The output that the future will produce on completion.
§

type IntoFuture = F

Which kind of future are we turning this into?
source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.