sync the various FromRawFd trait docs, and remove 'valid'

This commit is contained in:
Ralf Jung 2023-08-14 08:47:33 +02:00
parent a473e95786
commit b2b225e1d1
4 changed files with 32 additions and 21 deletions

View File

@ -85,7 +85,7 @@ pub trait FromRawFd {
/// # Safety /// # Safety
/// ///
/// The `fd` passed in must be an [owned file descriptor][io-safety]; /// The `fd` passed in must be an [owned file descriptor][io-safety];
/// in particular, it must be valid and open. /// in particular, it must be open.
/// ///
/// [io-safety]: io#io-safety /// [io-safety]: io#io-safety
/// ///

View File

@ -31,17 +31,22 @@ pub trait FromRawFd {
/// Constructs a new instance of `Self` from the given raw file /// Constructs a new instance of `Self` from the given raw file
/// descriptor and metadata. /// descriptor and metadata.
/// ///
/// This function **consumes [ownership][io-safety]** of the specified file /// This function is typically used to **consume ownership** of the
/// descriptor. The returned object will take responsibility for closing /// specified file descriptor. When used in this way, the returned object
/// it when the object goes out of scope. /// will take responsibility for closing it when the object goes out of
/// scope.
/// ///
/// [io-safety]: crate::io#io-safety /// However, consuming ownership is not strictly required. Use a
/// [`From<OwnedFd>::from`] implementation for an API which strictly
/// consumes ownership.
/// ///
/// This function is also unsafe as the primitives currently returned /// # Safety
/// have the contract that they are the sole owner of the file ///
/// descriptor they are wrapping. Usage of this function could /// The `fd` passed in must be an [owned file descriptor][io-safety];
/// accidentally allow violating this contract which can cause memory /// in particular, it must be open.
/// unsafety in code that relies on it being true. // FIXME: say something about `metadata`.
///
/// [io-safety]: io#io-safety
#[unstable(feature = "sgx_platform", issue = "56975")] #[unstable(feature = "sgx_platform", issue = "56975")]
unsafe fn from_raw_fd(fd: RawFd, metadata: Self::Metadata) -> Self; unsafe fn from_raw_fd(fd: RawFd, metadata: Self::Metadata) -> Self;
} }

View File

@ -27,17 +27,21 @@ pub trait FromRawFd {
/// Constructs a new instance of `Self` from the given raw file /// Constructs a new instance of `Self` from the given raw file
/// descriptor. /// descriptor.
/// ///
/// This function **consumes [ownership][io-safety]** of the specified file /// This function is typically used to **consume ownership** of the
/// descriptor. The returned object will take responsibility for closing /// specified file descriptor. When used in this way, the returned object
/// it when the object goes out of scope. /// will take responsibility for closing it when the object goes out of
/// scope.
/// ///
/// [io-safety]: crate::io#io-safety /// However, consuming ownership is not strictly required. Use a
/// [`From<OwnedFd>::from`] implementation for an API which strictly
/// consumes ownership.
/// ///
/// This function is also unsafe as the primitives currently returned /// # Safety
/// have the contract that they are the sole owner of the file ///
/// descriptor they are wrapping. Usage of this function could /// The `fd` passed in must be an [owned file descriptor][io-safety];
/// accidentally allow violating this contract which can cause memory /// in particular, it must be open.
/// unsafety in code that relies on it being true. ///
/// [io-safety]: io#io-safety
unsafe fn from_raw_fd(fd: RawFd) -> Self; unsafe fn from_raw_fd(fd: RawFd) -> Self;
} }

View File

@ -62,7 +62,7 @@ pub trait FromRawHandle {
/// # Safety /// # Safety
/// ///
/// The `handle` passed in must: /// The `handle` passed in must:
/// - be a valid an open handle, /// - be an [owned handle][io-safety]; in particular, it must be open.
/// - be a handle for a resource that may be freed via [`CloseHandle`] /// - be a handle for a resource that may be freed via [`CloseHandle`]
/// (as opposed to `RegCloseKey` or other close functions). /// (as opposed to `RegCloseKey` or other close functions).
/// ///
@ -71,6 +71,7 @@ pub trait FromRawHandle {
/// ///
/// [`CloseHandle`]: https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle /// [`CloseHandle`]: https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
/// [io-safety]: io#io-safety
#[stable(feature = "from_raw_os", since = "1.1.0")] #[stable(feature = "from_raw_os", since = "1.1.0")]
unsafe fn from_raw_handle(handle: RawHandle) -> Self; unsafe fn from_raw_handle(handle: RawHandle) -> Self;
} }
@ -207,10 +208,11 @@ pub trait FromRawSocket {
/// # Safety /// # Safety
/// ///
/// The `socket` passed in must: /// The `socket` passed in must:
/// - be a valid an open socket, /// - be an [owned socket][io-safety]; in particular, it must be open.
/// - be a socket that may be freed via [`closesocket`]. /// - be a socket that may be freed via [`closesocket`].
/// ///
/// [`closesocket`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-closesocket /// [`closesocket`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-closesocket
/// [io-safety]: io#io-safety
#[stable(feature = "from_raw_os", since = "1.1.0")] #[stable(feature = "from_raw_os", since = "1.1.0")]
unsafe fn from_raw_socket(sock: RawSocket) -> Self; unsafe fn from_raw_socket(sock: RawSocket) -> Self;
} }