11a0216d1Sopenharmony_ci//! io-lifetimes provides safe, convenient, and portable ways to temporarily
21a0216d1Sopenharmony_ci//! view an I/O resource as a `File`, `Socket`, or other types.
31a0216d1Sopenharmony_ci
41a0216d1Sopenharmony_ciuse io_lifetimes::AsFilelike;
51a0216d1Sopenharmony_ciuse std::fs::File;
61a0216d1Sopenharmony_ciuse std::io::{self, stdout};
71a0216d1Sopenharmony_ci
81a0216d1Sopenharmony_cifn main() -> io::Result<()> {
91a0216d1Sopenharmony_ci    let stdout = stdout();
101a0216d1Sopenharmony_ci
111a0216d1Sopenharmony_ci    // With `AsFilelike`, any type implementing `AsFd`/`AsHandle` can be viewed
121a0216d1Sopenharmony_ci    // as any type supporting `FromFilelike`, so you can call `File` methods on
131a0216d1Sopenharmony_ci    // `Stdout` or other things.
141a0216d1Sopenharmony_ci    //
151a0216d1Sopenharmony_ci    // Whether or not you can actually do this is up to the OS, of course. In
161a0216d1Sopenharmony_ci    // this case, Unix can do this, but it appears Windows can't.
171a0216d1Sopenharmony_ci    let metadata = stdout.as_filelike_view::<File>().metadata()?;
181a0216d1Sopenharmony_ci
191a0216d1Sopenharmony_ci    if metadata.is_file() {
201a0216d1Sopenharmony_ci        println!("stdout is a file!");
211a0216d1Sopenharmony_ci    } else {
221a0216d1Sopenharmony_ci        println!("stdout is not a file!");
231a0216d1Sopenharmony_ci    }
241a0216d1Sopenharmony_ci
251a0216d1Sopenharmony_ci    Ok(())
261a0216d1Sopenharmony_ci}
27