1 //! io-lifetimes provides safe, portable, and convenient conversions from types
2 //! implementing `IntoFilelike` and `FromSocketlike` to types implementing
3 //! `FromFilelike` and `IntoSocketlike`, respectively.
4 
5 use io_lifetimes::FromFilelike;
6 use std::fs::File;
7 use std::io::{self, Read};
8 use std::process::{Command, Stdio};
9 
mainnull10 fn main() -> io::Result<()> {
11     let mut child = Command::new("cargo")
12         .arg("--help")
13         .stdout(Stdio::piped())
14         .spawn()
15         .expect("failed to execute child");
16 
17     // Convert from `ChildStderr` into `File` without any platform-specific
18     // code or `unsafe`!
19     let mut file = File::from_into_filelike(child.stdout.take().unwrap());
20 
21     // Well, this example is not actually that cool, because `File` doesn't let
22     // you do anything that you couldn't already do with `ChildStderr` etc., but
23     // it's useful outside of standard library types.
24     let mut buffer = String::new();
25     file.read_to_string(&mut buffer)?;
26 
27     Ok(())
28 }
29