• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #[cfg(feature = "fs")]
2 #[cfg(not(target_os = "redox"))]
3 #[test]
test_owned()4 fn test_owned() {
5     use rustix::fd::{AsFd, AsRawFd, FromRawFd, IntoRawFd};
6 
7     let file = rustix::fs::openat(
8         rustix::fs::cwd(),
9         "Cargo.toml",
10         rustix::fs::OFlags::RDONLY,
11         rustix::fs::Mode::empty(),
12     )
13     .unwrap();
14 
15     let raw = file.as_raw_fd();
16     assert_eq!(raw, file.as_fd().as_raw_fd());
17 
18     let inner = file.into_raw_fd();
19     assert_eq!(raw, inner);
20 
21     let new = unsafe { rustix::fd::OwnedFd::from_raw_fd(inner) };
22     let mut buf = [0_u8; 4];
23     let _ = rustix::io::read(&new, &mut buf).unwrap();
24 }
25