1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use mio::Token;
use std::sync::atomic::{AtomicUsize, Ordering};

/// This trait defines a method for sequential generation of [`token`](Token)s
///
/// **Note**: This type is only available on platforms that support atomic loads and stores of usize
pub trait TokenSequence {
    /// generate next file description handle.
    fn next() -> Token {
        static NEXT: AtomicUsize = AtomicUsize::new(0);

        Token(NEXT.fetch_add(1, Ordering::SeqCst))
    }
}

impl TokenSequence for Token {}