11a0216d1Sopenharmony_ci//! io-lifetimes provides safe, portable, and convenient conversions from types 21a0216d1Sopenharmony_ci//! implementing `IntoFilelike` and `FromSocketlike` to types implementing 31a0216d1Sopenharmony_ci//! `FromFilelike` and `IntoSocketlike`, respectively. 41a0216d1Sopenharmony_ci 51a0216d1Sopenharmony_ciuse io_lifetimes::FromFilelike; 61a0216d1Sopenharmony_ciuse std::fs::File; 71a0216d1Sopenharmony_ciuse std::io::{self, Read}; 81a0216d1Sopenharmony_ciuse std::process::{Command, Stdio}; 91a0216d1Sopenharmony_ci 101a0216d1Sopenharmony_cifn main() -> io::Result<()> { 111a0216d1Sopenharmony_ci let mut child = Command::new("cargo") 121a0216d1Sopenharmony_ci .arg("--help") 131a0216d1Sopenharmony_ci .stdout(Stdio::piped()) 141a0216d1Sopenharmony_ci .spawn() 151a0216d1Sopenharmony_ci .expect("failed to execute child"); 161a0216d1Sopenharmony_ci 171a0216d1Sopenharmony_ci // Convert from `ChildStderr` into `File` without any platform-specific 181a0216d1Sopenharmony_ci // code or `unsafe`! 191a0216d1Sopenharmony_ci let mut file = File::from_into_filelike(child.stdout.take().unwrap()); 201a0216d1Sopenharmony_ci 211a0216d1Sopenharmony_ci // Well, this example is not actually that cool, because `File` doesn't let 221a0216d1Sopenharmony_ci // you do anything that you couldn't already do with `ChildStderr` etc., but 231a0216d1Sopenharmony_ci // it's useful outside of standard library types. 241a0216d1Sopenharmony_ci let mut buffer = String::new(); 251a0216d1Sopenharmony_ci file.read_to_string(&mut buffer)?; 261a0216d1Sopenharmony_ci 271a0216d1Sopenharmony_ci Ok(()) 281a0216d1Sopenharmony_ci} 29