Skip to content

Commit 5f68afb

Browse files
Backport the HandleOrInvalid patch from the PR.
Co-authored-by: Josh Triplett <[email protected]>
1 parent 695bee7 commit 5f68afb

File tree

6 files changed

+94
-135
lines changed

6 files changed

+94
-135
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl FromFd for OwnedFd { ... }
6868
```
6969

7070
On Windows, there are `Handle` and `Socket` versions of every `Fd` thing, and
71-
a special `OptionFileHandle` type to cope with inconsistent error reporting
71+
a special `HandleOrInvalid` type to cope with inconsistent error reporting
7272
in the Windows API.
7373

7474
Full API documentation:

examples/hello.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn main() -> io::Result<()> {
6969
#[cfg(windows)]
7070
fn main() -> io::Result<()> {
7171
let handle = unsafe {
72-
// Open a file, which returns an `OptionFileHandle`, which we can fallibly
72+
// Open a file, which returns an `HandleOrInvalid`, which we can fallibly
7373
// convert into an `OwnedFile`.
7474
let handle: OwnedHandle = CreateFileW(
7575
['C' as u16, 'O' as _, 'N' as _, 0].as_ptr(),

src/example_ffi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#[cfg(any(unix, target_os = "wasi"))]
1111
use crate::{BorrowedFd, OwnedFd};
1212
#[cfg(windows)]
13-
use crate::{BorrowedHandle, OptionFileHandle, OwnedHandle};
13+
use crate::{BorrowedHandle, HandleOrInvalid, OwnedHandle};
1414

1515
#[cfg(any(unix, target_os = "wasi"))]
1616
use libc::{c_char, c_int, c_void, size_t, ssize_t};
@@ -35,7 +35,7 @@ extern "C" {
3535
#[cfg(any(unix, target_os = "wasi"))]
3636
pub use libc::{O_CLOEXEC, O_CREAT, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY};
3737

38-
/// The Windows analogs of the above. Note the use of [`OptionFileHandle`] as
38+
/// The Windows analogs of the above. Note the use of [`HandleOrInvalid`] as
3939
/// the return type for `CreateFileW`, since that function is defined to return
4040
/// [`INVALID_HANDLE_VALUE`] on error instead of null.
4141
#[cfg(windows)]
@@ -48,7 +48,7 @@ extern "C" {
4848
dwCreationDisposition: DWORD,
4949
dwFlagsAndAttributes: DWORD,
5050
hTemplateFile: HANDLE,
51-
) -> OptionFileHandle;
51+
) -> HandleOrInvalid;
5252
pub fn ReadFile(
5353
hFile: HANDLE,
5454
lpBuffer: LPVOID,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub use traits::{AsHandle, AsSocket, FromHandle, FromSocket, IntoHandle, IntoSoc
4343
#[cfg(any(unix, target_os = "wasi"))]
4444
pub use types::{BorrowedFd, OwnedFd};
4545
#[cfg(windows)]
46-
pub use types::{BorrowedHandle, BorrowedSocket, OptionFileHandle, OwnedHandle, OwnedSocket};
46+
pub use types::{BorrowedHandle, BorrowedSocket, HandleOrInvalid, OwnedHandle, OwnedSocket};
4747

4848
pub use portability::{
4949
AsFilelike, AsSocketlike, BorrowedFilelike, BorrowedSocketlike, FromFilelike, FromSocketlike,

src/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(any(unix, target_os = "wasi"))]
22
use crate::{BorrowedFd, OwnedFd};
33
#[cfg(windows)]
4-
use crate::{BorrowedHandle, BorrowedSocket, OptionFileHandle, OwnedHandle, OwnedSocket};
4+
use crate::{BorrowedHandle, BorrowedSocket, HandleOrInvalid, OwnedHandle, OwnedSocket};
55
#[cfg(unix)]
66
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
77
#[cfg(target_os = "wasi")]
@@ -307,7 +307,7 @@ impl FromSocket for OwnedSocket {
307307
}
308308

309309
#[cfg(windows)]
310-
impl FromHandle for OptionFileHandle {
310+
impl FromHandle for HandleOrInvalid {
311311
#[inline]
312312
fn from_handle(owned: OwnedHandle) -> Self {
313313
unsafe { Self::from_raw_handle(owned.into_raw_handle()) }

0 commit comments

Comments
 (0)