mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-12 06:53:05 +00:00
Make BorrowedFd::borrow_raw
a const fn.
Making `BorrowedFd::borrow_raw` a const fn allows it to be used to create a constant `BorrowedFd<'static>` holding constants such as `AT_FDCWD`. This will allow [`rustix::fs::cwd`] to become a const fn. For consistency, make similar changes to `BorrowedHandle::borrow_raw` and `BorrowedSocket::borrow_raw`. [`rustix::fs::cwd`]: https://docs.rs/rustix/latest/rustix/fs/fn.cwd.html
This commit is contained in:
parent
d5ae66c12c
commit
0a1ce8277c
@ -66,8 +66,8 @@ impl BorrowedFd<'_> {
|
|||||||
/// the returned `BorrowedFd`, and it must not have the value `-1`.
|
/// the returned `BorrowedFd`, and it must not have the value `-1`.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "io_safety", issue = "87074")]
|
#[unstable(feature = "io_safety", issue = "87074")]
|
||||||
pub unsafe fn borrow_raw(fd: RawFd) -> Self {
|
pub const unsafe fn borrow_raw(fd: RawFd) -> Self {
|
||||||
assert_ne!(fd, u32::MAX as RawFd);
|
assert!(fd != u32::MAX as RawFd);
|
||||||
// SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
|
// SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
|
||||||
unsafe { Self { fd, _phantom: PhantomData } }
|
unsafe { Self { fd, _phantom: PhantomData } }
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ impl BorrowedHandle<'_> {
|
|||||||
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
|
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "io_safety", issue = "87074")]
|
#[unstable(feature = "io_safety", issue = "87074")]
|
||||||
pub unsafe fn borrow_raw(handle: RawHandle) -> Self {
|
pub const unsafe fn borrow_raw(handle: RawHandle) -> Self {
|
||||||
Self { handle, _phantom: PhantomData }
|
Self { handle, _phantom: PhantomData }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ impl BorrowedSocket<'_> {
|
|||||||
/// `INVALID_SOCKET`.
|
/// `INVALID_SOCKET`.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "io_safety", issue = "87074")]
|
#[unstable(feature = "io_safety", issue = "87074")]
|
||||||
pub unsafe fn borrow_raw(socket: RawSocket) -> Self {
|
pub const unsafe fn borrow_raw(socket: RawSocket) -> Self {
|
||||||
debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket);
|
assert!(socket != c::INVALID_SOCKET as RawSocket);
|
||||||
Self { socket, _phantom: PhantomData }
|
Self { socket, _phantom: PhantomData }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user