1//! io-lifetimes provides safe, convenient, and portable ways to temporarily 2//! view an I/O resource as a `File`, `Socket`, or other types. 3 4use io_lifetimes::AsFilelike; 5use std::fs::File; 6use std::io::{self, stdout}; 7 8fn main() -> io::Result<()> { 9 let stdout = stdout(); 10 11 // With `AsFilelike`, any type implementing `AsFd`/`AsHandle` can be viewed 12 // as any type supporting `FromFilelike`, so you can call `File` methods on 13 // `Stdout` or other things. 14 // 15 // Whether or not you can actually do this is up to the OS, of course. In 16 // this case, Unix can do this, but it appears Windows can't. 17 let metadata = stdout.as_filelike_view::<File>().metadata()?; 18 19 if metadata.is_file() { 20 println!("stdout is a file!"); 21 } else { 22 println!("stdout is not a file!"); 23 } 24 25 Ok(()) 26} 27