AsyncIO

Trait AsyncIO 

Source
pub trait AsyncIO {
    type AsyncFd<T: AsRawFd + AsFd + Send + Sync + 'static>: AsyncFd<T>;

    // Required methods
    fn connect_tcp(
        addr: &SocketAddr,
    ) -> impl Future<Output = Result<Self::AsyncFd<TcpStream>>> + Send;
    fn connect_unix(
        addr: &PathBuf,
    ) -> impl Future<Output = Result<Self::AsyncFd<UnixStream>>> + Send;
    fn to_async_fd_rd<T: AsRawFd + AsFd + Send + Sync + 'static>(
        fd: T,
    ) -> Result<Self::AsyncFd<T>>;
    fn to_async_fd_rw<T: AsRawFd + AsFd + Send + Sync + 'static>(
        fd: T,
    ) -> Result<Self::AsyncFd<T>>;
}
Expand description

Trait for async I/O operations.

This trait defines the interface for performing asynchronous I/O operations such as connecting to network services and converting file descriptors to async handles.

§Associated Types

  • AsyncFd - The type used to represent async file descriptors

Required Associated Types§

Source

type AsyncFd<T: AsRawFd + AsFd + Send + Sync + 'static>: AsyncFd<T>

The type used to represent async file descriptors.

This associated type represents a wrapper around a file descriptor that provides async read/write operations.

Required Methods§

Source

fn connect_tcp( addr: &SocketAddr, ) -> impl Future<Output = Result<Self::AsyncFd<TcpStream>>> + Send

Connect to a TCP address asynchronously.

§NOTE

This is for runtime implementation, for user should use TcpStream::<IO>::connect() instead**.

This method attempts to establish a TCP connection to the specified address, returning an async file descriptor that can be used for communication.

§Parameters
  • addr - The socket address to connect to
§Returns

A future that resolves to a Result containing either the connected async file descriptor or an I/O error.

Source

fn connect_unix( addr: &PathBuf, ) -> impl Future<Output = Result<Self::AsyncFd<UnixStream>>> + Send

Connect to a Unix socket address asynchronously.

§NOTE

This is for runtime implementation, for user should use UnixStream::<IO>::connect() instead**.

This method attempts to establish a Unix socket connection to the specified path, returning an async file descriptor that can be used for communication.

§Parameters
  • addr - The path to the Unix socket
§Returns

A future that resolves to a Result containing either the connected async file descriptor or an I/O error.

Source

fn to_async_fd_rd<T: AsRawFd + AsFd + Send + Sync + 'static>( fd: T, ) -> Result<Self::AsyncFd<T>>

Wrap a readable file object as an async handle

The file descriptor will subscribe for read to the runtime poller

§Parameters
  • fd - The file descriptor to wrap
§Returns

A Result containing either the async file descriptor handle or an I/O error.

§Safety

The file descriptor must be set to non-blocking mode before calling this method.

Source

fn to_async_fd_rw<T: AsRawFd + AsFd + Send + Sync + 'static>( fd: T, ) -> Result<Self::AsyncFd<T>>

Wrap a readable/writable file object as an async handle.

The file descriptor will subscribe for read + write to the runtime poller

§Parameters
  • fd - The file descriptor to wrap
§Returns

A Result containing either the async file descriptor handle or an I/O error.

§Safety

The file descriptor must be set to non-blocking mode before calling this method.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F: Deref<Target = IO>, IO: AsyncIO> AsyncIO for F

Source§

type AsyncFd<T: AsRawFd + AsFd + Send + Sync + 'static> = <IO as AsyncIO>::AsyncFd<T>