Struct 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>,

Source§

type Output = O

The type of value produced on completion.
Source§

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

Attempts 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> Freeze for Select<Bits, S, B, T>
where S: Freeze, B: Freeze, T: Freeze, Bits: Freeze,

§

impl<Bits, S, B, T> RefUnwindSafe for Select<Bits, S, B, T>

§

impl<Bits, S, B, T> Send for Select<Bits, S, B, T>
where S: Send, B: Send, T: Send, Bits: Send,

§

impl<Bits, S, B, T> Sync for Select<Bits, S, B, T>
where S: Sync, B: Sync, T: Sync, Bits: Sync,

§

impl<Bits, S, B, T> Unpin for Select<Bits, S, B, T>
where S: Unpin, B: Unpin, T: Unpin, Bits: Unpin,

§

impl<Bits, S, B, T> UnwindSafe for Select<Bits, S, B, T>
where S: UnwindSafe, B: UnwindSafe, T: UnwindSafe, Bits: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.