From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/io-lifetimes/examples/easy-conversions.rs | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 vendor/io-lifetimes/examples/easy-conversions.rs (limited to 'vendor/io-lifetimes/examples/easy-conversions.rs') diff --git a/vendor/io-lifetimes/examples/easy-conversions.rs b/vendor/io-lifetimes/examples/easy-conversions.rs new file mode 100644 index 000000000..87481c12f --- /dev/null +++ b/vendor/io-lifetimes/examples/easy-conversions.rs @@ -0,0 +1,30 @@ +//! io-lifetimes provides safe, portable, and convenient conversions from types +//! implementing `IntoFilelike` and `FromSocketlike` to types implementing +//! `FromFilelike` and `IntoSocketlike`, respectively. + +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +use io_lifetimes::FromFilelike; +use std::fs::File; +use std::io::{self, Read}; +use std::process::{Command, Stdio}; + +fn main() -> io::Result<()> { + let mut child = Command::new("cargo") + .arg("--help") + .stdout(Stdio::piped()) + .spawn() + .expect("failed to execute child"); + + // Convert from `ChildStderr` into `File` without any platform-specific + // code or `unsafe`! + let mut file = File::from_into_filelike(child.stdout.take().unwrap()); + + // Well, this example is not actually that cool, because `File` doesn't let + // you do anything that you couldn't already do with `ChildStderr` etc., but + // it's useful outside of standard library types. + let mut buffer = String::new(); + file.read_to_string(&mut buffer)?; + + Ok(()) +} -- cgit v1.2.3