forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#93663 - sunfishcode:sunfishcode/as-raw-name…
…, r=joshtriplett Rename `BorrowedFd::borrow_raw_fd` to `BorrowedFd::borrow_raw`. Also, rename `BorrowedHandle::borrow_raw_handle` and `BorrowedSocket::borrow_raw_socket` to `BorrowedHandle::borrow_raw` and `BorrowedSocket::borrow_raw`. This is just a minor rename to reduce redundancy in the user code calling these functions, and to eliminate an inessential difference between `BorrowedFd` code and `BorrowedHandle`/`BorrowedSocket` code. While here, add a simple test exercising `BorrowedFd::borrow_raw_fd`. r? `@joshtriplett`
- Loading branch information
Showing
6 changed files
with
62 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ pub mod owned; | |
|
||
// Implementations for `AsRawFd` etc. for network types. | ||
mod net; | ||
|
||
#[cfg(test)] | ||
mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#[cfg(any(unix, target_os = "wasi"))] | ||
#[test] | ||
fn test_raw_fd() { | ||
#[cfg(unix)] | ||
use crate::os::unix::io::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; | ||
#[cfg(target_os = "wasi")] | ||
use crate::os::wasi::io::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; | ||
|
||
let raw_fd: RawFd = crate::io::stdin().as_raw_fd(); | ||
|
||
let stdin_as_file = unsafe { crate::fs::File::from_raw_fd(raw_fd) }; | ||
assert_eq!(stdin_as_file.as_raw_fd(), raw_fd); | ||
assert_eq!(unsafe { BorrowedFd::borrow_raw(raw_fd).as_raw_fd() }, raw_fd); | ||
assert_eq!(stdin_as_file.into_raw_fd(), 0); | ||
} | ||
|
||
#[cfg(any(unix, target_os = "wasi"))] | ||
#[test] | ||
fn test_fd() { | ||
#[cfg(unix)] | ||
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; | ||
#[cfg(target_os = "wasi")] | ||
use crate::os::wasi::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; | ||
|
||
let stdin = crate::io::stdin(); | ||
let fd: BorrowedFd<'_> = stdin.as_fd(); | ||
let raw_fd: RawFd = fd.as_raw_fd(); | ||
let owned_fd: OwnedFd = unsafe { OwnedFd::from_raw_fd(raw_fd) }; | ||
|
||
let stdin_as_file = crate::fs::File::from(owned_fd); | ||
|
||
assert_eq!(stdin_as_file.as_fd().as_raw_fd(), raw_fd); | ||
assert_eq!(Into::<OwnedFd>::into(stdin_as_file).into_raw_fd(), raw_fd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters