Skip to content

Commit d6b838b

Browse files
Simplify fd examples
1 parent 980e1ff commit d6b838b

File tree

1 file changed

+16
-19
lines changed
  • library/std/src/sys/unix/ext

1 file changed

+16
-19
lines changed

library/std/src/sys/unix/ext/io.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ pub trait AsRawFd {
3030
///
3131
/// ```no_run
3232
/// use std::fs::File;
33+
/// # use std::io;
3334
/// use std::os::unix::io::{AsRawFd, RawFd};
3435
///
35-
/// fn main() -> std::io::Result<()> {
36-
/// let mut f = File::open("foo.txt")?;
37-
/// // Note that `raw_fd` is only valid as long as `f` exists.
38-
/// let raw_fd: RawFd = f.as_raw_fd();
39-
/// Ok(())
40-
/// }
36+
/// let mut f = File::open("foo.txt")?;
37+
/// // Note that `raw_fd` is only valid as long as `f` exists.
38+
/// let raw_fd: RawFd = f.as_raw_fd();
39+
/// # Ok::<(), io::Error>(())
4140
/// ```
4241
#[stable(feature = "rust1", since = "1.0.0")]
4342
fn as_raw_fd(&self) -> RawFd;
@@ -64,16 +63,15 @@ pub trait FromRawFd {
6463
///
6564
/// ```no_run
6665
/// use std::fs::File;
66+
/// # use std::io;
6767
/// use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
6868
///
69-
/// fn main() -> std::io::Result<()> {
70-
/// let f = File::open("foo.txt")?;
71-
/// let raw_fd: RawFd = f.into_raw_fd();
72-
/// // SAFETY: no other functions should call `from_raw_fd`, so there
73-
/// // is only one owner for the file descriptor.
74-
/// let f = unsafe { File::from_raw_fd(raw_fd) };
75-
/// Ok(())
76-
/// }
69+
/// let f = File::open("foo.txt")?;
70+
/// let raw_fd: RawFd = f.into_raw_fd();
71+
/// // SAFETY: no other functions should call `from_raw_fd`, so there
72+
/// // is only one owner for the file descriptor.
73+
/// let f = unsafe { File::from_raw_fd(raw_fd) };
74+
/// # Ok::<(), io::Error>(())
7775
/// ```
7876
#[stable(feature = "from_raw_os", since = "1.1.0")]
7977
unsafe fn from_raw_fd(fd: RawFd) -> Self;
@@ -93,13 +91,12 @@ pub trait IntoRawFd {
9391
///
9492
/// ```no_run
9593
/// use std::fs::File;
94+
/// # use std::io;
9695
/// use std::os::unix::io::{IntoRawFd, RawFd};
9796
///
98-
/// fn main() -> std::io::Result<()> {
99-
/// let f = File::open("foo.txt")?;
100-
/// let raw_fd: RawFd = f.into_raw_fd();
101-
/// Ok(())
102-
/// }
97+
/// let f = File::open("foo.txt")?;
98+
/// let raw_fd: RawFd = f.into_raw_fd();
99+
/// # Ok::<(), io::Error>(())
103100
/// ```
104101
#[stable(feature = "into_raw_os", since = "1.4.0")]
105102
fn into_raw_fd(self) -> RawFd;

0 commit comments

Comments
 (0)