splice

Function splice 

Source
pub fn splice<I, O>(
    fd_in: &impl ToSharedFd<I>,
    fd_out: &impl ToSharedFd<O>,
    len: usize,
) -> Splice<I, O>
where I: AsFd + 'static, O: AsFd + 'static,
Available on crate feature fs and Unix only.
Expand description

Splice data between two file descriptors without copying through userspace.

At least one of fd_in or fd_out must be a pipe. Returns a builder that can be configured with optional offsets and flags before awaiting.

§Example

const HELLO: &[u8] = b"hello world";

let mut tempfile = tempfile();
tempfile.write_all(HELLO).unwrap();

let file = File::open(tempfile.path()).await.unwrap();
let (mut rx, tx) = anonymous().unwrap();

let n = splice(&file, &tx, HELLO.len()).offset_in(0).await.unwrap();
assert_eq!(n, HELLO.len());

drop(tx);
let (_, buf) = rx
   .read_exact(Vec::with_capacity(HELLO.len()))
   .await
   .unwrap();
assert_eq!(&buf, HELLO);