Enum popol::Timeout

source ·
pub enum Timeout {
    After(Duration),
    Never,
}
Expand description

Optional timeout.

Note that the maximum timeout is i32::MAX milliseconds (about 25 days). Longer timeouts will be silently clipped to i32::MAX milliseconds.

Variants§

§

After(Duration)

Timeout after a specific duration.

§

Never

Never timeout.

Implementations§

source§

impl Timeout

source

pub fn from_secs(seconds: u32) -> Self

Create a timeout with the specified number of seconds.

See Timeout for an important note about the maximum timeout.

Examples found in repository?
examples/stdin.rs (line 14)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> io::Result<()> {
    // Create a registry to hold I/O sources.
    let mut sources = popol::Sources::with_capacity(1);
    // Create an events buffer to hold readiness events.
    let mut events = Vec::with_capacity(1);

    // Register the program's standard input as a source of "read" readiness events.
    sources.register((), &io::stdin(), popol::interest::READ);

    // Wait on our event sources for at most 6 seconds. If an event source is
    // ready before then, process its events. Otherwise, timeout.
    match sources.poll(&mut events, popol::Timeout::from_secs(6)) {
        Ok(_) => {}
        Err(err) if err.kind() == io::ErrorKind::TimedOut => process::exit(1),
        Err(err) => return Err(err),
    }

    // Iterate over source events. Since we only have one source
    // registered, this will only iterate once.
    for event in events.drain(..) {
        // An error occured with the standard input.
        if event.is_error() {
            panic!("error on {:?}", io::stdin());
        }
        // The standard input has data ready to be read.
        if event.is_readable() || event.is_hangup() {
            let mut buf = [0; 1024];

            // Read what we can from standard input and echo it.
            match io::stdin().read(&mut buf[..]) {
                Ok(n) => io::stdout().write_all(&buf[..n])?,
                Err(err) => panic!("{}", err),
            }
        }
    }

    Ok(())
}
source

pub fn from_millis(milliseconds: u32) -> Self

Create a timeout with the specified number of milliseconds.

See Timeout for an important note about the maximum timeout.

Trait Implementations§

source§

impl Clone for Timeout

source§

fn clone(&self) -> Timeout

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Timeout

source§

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

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

impl From<Duration> for Timeout

source§

fn from(duration: Duration) -> Self

Create a timeout from a duration.

See Timeout for an important note about the maximum timeout.

source§

impl From<Option<Duration>> for Timeout

source§

fn from(duration: Option<Duration>) -> Self

Create a timeout from an optional duration.

See Timeout for an important note about the maximum timeout.

Auto Trait Implementations§

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
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.
source§

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

Performs the conversion.