async_std/os/windows/
io.rs

1//! Windows-specific I/O extensions.
2
3cfg_not_docs! {
4    pub use std::os::windows::io::{
5        AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle, RawSocket,
6    };
7}
8
9cfg_docs! {
10    /// Raw HANDLEs.
11    pub type RawHandle = *mut std::os::raw::c_void;
12
13    /// Raw SOCKETs.
14    pub type RawSocket = u64;
15
16    /// Extracts raw handles.
17    pub trait AsRawHandle {
18        /// Extracts the raw handle, without taking any ownership.
19        fn as_raw_handle(&self) -> RawHandle;
20    }
21
22    /// Construct I/O objects from raw handles.
23    pub trait FromRawHandle {
24        /// Constructs a new I/O object from the specified raw handle.
25        ///
26        /// This function will **consume ownership** of the handle given,
27        /// passing responsibility for closing the handle to the returned
28        /// object.
29        ///
30        /// This function is also unsafe as the primitives currently returned
31        /// have the contract that they are the sole owner of the file
32        /// descriptor they are wrapping. Usage of this function could
33        /// accidentally allow violating this contract which can cause memory
34        /// unsafety in code that relies on it being true.
35        unsafe fn from_raw_handle(handle: RawHandle) -> Self;
36    }
37
38    /// A trait to express the ability to consume an object and acquire ownership of
39    /// its raw `HANDLE`.
40    pub trait IntoRawHandle {
41        /// Consumes this object, returning the raw underlying handle.
42        ///
43        /// This function **transfers ownership** of the underlying handle to the
44        /// caller. Callers are then the unique owners of the handle and must close
45        /// it once it's no longer needed.
46        fn into_raw_handle(self) -> RawHandle;
47    }
48}