crossio-core 0.1.0

Core abstractions for the crossio async I/O backend
Documentation
//! Registration helpers and traits for reactor sources.
use crate::{backend::Backend, interest::Interest, token::Token};

/// Describes the readiness configuration associated with a registered source.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Registration {
    token: Token,
    interest: Interest,
}

impl Registration {
    /// Builds a new registration from the provided token and interest.
    pub const fn new(token: Token, interest: Interest) -> Self {
        Self { token, interest }
    }

    /// Returns the token tied to this registration.
    pub const fn token(&self) -> Token {
        self.token
    }

    /// Returns the current interest mask.
    pub const fn interest(&self) -> Interest {
        self.interest
    }

    /// Creates a new registration with an updated interest mask.
    pub const fn with_interest(self, interest: Interest) -> Self {
        Self {
            token: self.token,
            interest,
        }
    }
}

/// Trait implemented by platform-specific sources (sockets, pipes, etc.).
pub trait Source<B: Backend>: Send + Sync {
    /// Returns the raw descriptor understood by the backend.
    fn raw_source(&self) -> B::RawSource;
}