33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
55
6- //! Thin pipe- related wrappers around functions from the `nix ` crate.
7-
6+ //! Thin zero-copy- related wrappers around functions from the `rustix ` crate.
7+ # [ cfg ( any ( target_os = "linux" , target_os = "android" ) ) ]
88use std:: fs:: File ;
99#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1010use std:: os:: fd:: AsFd ;
1111
1212#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
13- use nix :: fcntl :: SpliceFFlags ;
13+ use rustix :: pipe :: SpliceFlags ;
1414
15- pub use nix:: { Error , Result } ;
16-
17- /// A wrapper around [`nix::unistd::pipe`] that ensures the pipe is cleaned up.
15+ /// A wrapper around [`rustix::pipe::pipe`] that ensures the pipe is cleaned up.
1816///
1917/// Returns two `File` objects: everything written to the second can be read
2018/// from the first.
21- pub fn pipe ( ) -> Result < ( File , File ) > {
22- let ( read, write) = nix:: unistd:: pipe ( ) ?;
19+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
20+ pub fn pipe ( ) -> std:: io:: Result < ( File , File ) > {
21+ let ( read, write) = rustix:: pipe:: pipe ( ) ?;
2322 Ok ( ( File :: from ( read) , File :: from ( write) ) )
2423}
2524
26- /// Less noisy wrapper around [`nix::fcntl ::splice`].
25+ /// Less noisy wrapper around [`rustix::pipe ::splice`].
2726///
2827/// Up to `len` bytes are moved from `source` to `target`. Returns the number
2928/// of successfully moved bytes.
@@ -33,8 +32,15 @@ pub fn pipe() -> Result<(File, File)> {
3332/// a [`pipe`] and then from the pipe into your target (with `splice_exact`):
3433/// this is still very efficient.
3534#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
36- pub fn splice ( source : & impl AsFd , target : & impl AsFd , len : usize ) -> Result < usize > {
37- nix:: fcntl:: splice ( source, None , target, None , len, SpliceFFlags :: empty ( ) )
35+ pub fn splice ( source : & impl AsFd , target : & impl AsFd , len : usize ) -> std:: io:: Result < usize > {
36+ Ok ( rustix:: pipe:: splice (
37+ source,
38+ None ,
39+ target,
40+ None ,
41+ len,
42+ SpliceFlags :: empty ( ) ,
43+ ) ?)
3844}
3945
4046/// Splice wrapper which fully finishes the write.
@@ -43,11 +49,11 @@ pub fn splice(source: &impl AsFd, target: &impl AsFd, len: usize) -> Result<usiz
4349///
4450/// Panics if `source` runs out of data before `len` bytes have been moved.
4551#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
46- pub fn splice_exact ( source : & impl AsFd , target : & impl AsFd , len : usize ) -> Result < ( ) > {
52+ pub fn splice_exact ( source : & impl AsFd , target : & impl AsFd , len : usize ) -> std :: io :: Result < ( ) > {
4753 let mut left = len;
4854 while left != 0 {
4955 let written = splice ( source, target, left) ?;
50- assert_ne ! ( written, 0 , "unexpected end of data" ) ;
56+ debug_assert_ne ! ( written, 0 , "unexpected end of data" ) ;
5157 left -= written;
5258 }
5359 Ok ( ( ) )
0 commit comments