crossio-core 0.1.0

Core abstractions for the crossio async I/O backend
Documentation
//! Trait definitions shared by every backend implementation.
use crate::{
    config::BackendConfig,
    error::CrossioError,
    event::Events,
    interest::Interest,
    token::Token,
};
use std::time::Duration;

/// Contract implemented by each platform-specific polling backend.
pub trait Backend: Send + Sync {
    /// Platform-native descriptor type understood by this backend.
    type RawSource: Copy + Send + Sync + 'static;

    /// Builds a new backend using the provided configuration knobs.
    fn new(config: BackendConfig) -> Result<Self, CrossioError>
    where
        Self: Sized;

    /// Registers a source with the backend so future readiness changes are reported.
    fn register(
        &self,
        source: Self::RawSource,
        token: Token,
        interest: Interest,
    ) -> Result<(), CrossioError>;

    /// Updates the interest mask associated with a previously registered source.
    fn reregister(
        &self,
        source: Self::RawSource,
        token: Token,
        interest: Interest,
    ) -> Result<(), CrossioError>;

    /// Removes a source from the backend, cancelling any future readiness notifications.
    fn deregister(&self, source: Self::RawSource) -> Result<(), CrossioError>;

    /// Polls for readiness notifications, filling `events` and returning the number of entries.
    fn poll(
        &self,
        events: &mut Events,
        timeout: Option<Duration>,
    ) -> Result<usize, CrossioError>;
}