Fix doc test failures on Windows.

This commit is contained in:
Dan Gohman 2021-08-19 16:15:29 -07:00
parent e555003e6d
commit b4dfa198bf
3 changed files with 7 additions and 1 deletions

View File

@ -159,6 +159,7 @@ pub trait AsFd {
/// # use std::os::unix::io::{AsFd, BorrowedFd};
///
/// let mut f = File::open("foo.txt")?;
/// # #[cfg(any(unix, target_os = "wasi"))]
/// let borrowed_fd: BorrowedFd<'_> = f.as_fd();
/// # Ok::<(), io::Error>(())
/// ```

View File

@ -40,6 +40,7 @@ pub trait AsRawFd {
///
/// let mut f = File::open("foo.txt")?;
/// // Note that `raw_fd` is only valid as long as `f` exists.
/// #[cfg(any(unix, target_os = "wasi"))]
/// let raw_fd: RawFd = f.as_raw_fd();
/// # Ok::<(), io::Error>(())
/// ```
@ -75,9 +76,11 @@ pub trait FromRawFd {
/// use std::os::wasi::io::{FromRawFd, IntoRawFd, RawFd};
///
/// let f = File::open("foo.txt")?;
/// # #[cfg(any(unix, target_os = "wasi"))]
/// let raw_fd: RawFd = f.into_raw_fd();
/// // SAFETY: no other functions should call `from_raw_fd`, so there
/// // is only one owner for the file descriptor.
/// # #[cfg(any(unix, target_os = "wasi"))]
/// let f = unsafe { File::from_raw_fd(raw_fd) };
/// # Ok::<(), io::Error>(())
/// ```
@ -106,6 +109,7 @@ pub trait IntoRawFd {
/// use std::os::wasi::io::{IntoRawFd, RawFd};
///
/// let f = File::open("foo.txt")?;
/// #[cfg(any(unix, target_os = "wasi"))]
/// let raw_fd: RawFd = f.into_raw_fd();
/// # Ok::<(), io::Error>(())
/// ```

View File

@ -237,9 +237,10 @@ pub trait AsHandle {
/// # Example
///
/// ```rust,no_run
/// # #![feature(io_safety)]
/// use std::fs::File;
/// # use std::io;
/// use std::os::windows::{AsHandle, BorrowedHandle};
/// use std::os::windows::io::{AsHandle, BorrowedHandle};
///
/// let mut f = File::open("foo.txt")?;
/// let borrowed_handle: BorrowedHandle<'_> = f.as_handle();