#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
#[cfg(all(feature = "close", not(windows)))]
use io_lifetimes::{AsFd, BorrowedFd, IntoFd, OwnedFd};
#[cfg(all(feature = "close", not(windows)))]
fn use_fd_a(fd: BorrowedFd<'_>) {
let _ = fd;
}
#[cfg(all(feature = "close", not(windows)))]
fn use_fd_b<Fd: AsFd>(fd: &Fd) {
let _ = fd.as_fd();
}
#[cfg(all(feature = "close", not(windows)))]
fn consume_fd_a(fd: OwnedFd) {
let _ = fd;
}
#[cfg(all(feature = "close", not(windows)))]
fn consume_fd_b<Fd: IntoFd>(fd: Fd) {
let _ = fd.into_fd();
}
#[cfg(all(feature = "close", not(windows)))]
fn main() {
let f = std::fs::File::open("Cargo.toml").unwrap();
use_fd_a(f.as_fd());
use_fd_b(&f);
use_fd_b(&f.as_fd());
let a = std::fs::File::open("Cargo.toml").unwrap();
let b = std::fs::File::open("Cargo.toml").unwrap();
consume_fd_a(a.into_fd());
consume_fd_b(b);
}
#[cfg(windows)]
fn main() {
println!("This example uses non-Windows APIs.");
}
#[cfg(all(not(feature = "close"), not(windows)))]
fn main() {
println!("This example requires the \"close\" feature.");
}