Trait IoSafe

Source
pub unsafe trait IoSafe { }
Expand description

Types whose I/O trait implementations do not move or drop the underlying I/O object

The I/O object inside Async cannot be closed before the Async is dropped, because [Async] deregisters the I/O object from the reactor on drop. Closing the I/O before deregistering leads to the reactor holding a dangling I/O handle, which violates I/O safety.

As such, functions that grant mutable access to the inner I/O object are unsafe, because they may move or drop the underlying I/O. Unfortunately, Async needs to call I/O traits such as Read and Write to implement the async version of those traits.

To signal that those traits are safe to implement for an I/O type, it must implement IoSafe, which acts as a promise that the I/O type doesn’t move or drop itself in its I/O trait implementations.

This trait is implemented for std I/O types.

§Safety

Implementors of IoSafe must not drop or move its underlying I/O source in its implementations of Read, Write, and BufRead. Specifically, the “underlying I/O source” is defined as the I/O primitive corresponding to the type’s AsFd/AsSocket implementation.

Implementations on Foreign Types§

Source§

impl IoSafe for File

Source§

impl IoSafe for Stderr

Source§

impl IoSafe for StderrLock<'_>

Source§

impl IoSafe for Stdin

Source§

impl IoSafe for StdinLock<'_>

Source§

impl IoSafe for Stdout

Source§

impl IoSafe for StdoutLock<'_>

Source§

impl IoSafe for TcpStream

Source§

impl IoSafe for UdpSocket

Source§

impl IoSafe for UnixStream

Source§

impl IoSafe for ChildStderr

Source§

impl IoSafe for ChildStdin

Source§

impl IoSafe for ChildStdout

Source§

impl<T: IoSafe + Write> IoSafe for BufWriter<T>

Source§

impl<T: IoSafe + Write> IoSafe for LineWriter<T>

Source§

impl<T: IoSafe + ?Sized> IoSafe for &T

IoSafe cannot be unconditionally implemented for references, because non-mutable references can still drop or move internal fields via interior mutability.

Source§

impl<T: IoSafe + ?Sized> IoSafe for &mut T

Source§

impl<T: IoSafe + ?Sized> IoSafe for Box<T>

Source§

impl<T: IoSafe> IoSafe for BufReader<T>

Implementors§