use std::{ env, fs, io::{self, Read as _, Write as _}, net::TcpStream, path::PathBuf, }; fn main() -> io::Result<()> { let mut v = Vec::new(); let mut server = TcpStream::connect("example.com:80")?; server.write_all("GET / HTTP/1.0\r\nHost: example.com\r\n\r\n".as_bytes())?; server.read_to_end(&mut v)?; let example = PathBuf::from(env::var("OUT_DIR").expect("build script always has OUT_DIR set")) .join("example"); fs::write(&example, v)?; println!("cargo:warning=wrote {}", example.display()); Ok(()) }