1 use crate::backend::c; 2 use bitflags::bitflags; 3 use core::marker::PhantomData; 4 5 bitflags! { 6 /// `O_*` constants for use with [`pipe_with`]. 7 /// 8 /// [`pipe_with`]: crate::pipe::pipe_with 9 #[repr(transparent)] 10 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 11 pub struct PipeFlags: c::c_uint { 12 /// `O_CLOEXEC` 13 const CLOEXEC = linux_raw_sys::general::O_CLOEXEC; 14 /// `O_DIRECT` 15 const DIRECT = linux_raw_sys::general::O_DIRECT; 16 /// `O_NONBLOCK` 17 const NONBLOCK = linux_raw_sys::general::O_NONBLOCK; 18 19 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 20 const _ = !0; 21 } 22 } 23 24 bitflags! { 25 /// `SPLICE_F_*` constants for use with [`splice`], [`vmsplice`], and 26 /// [`tee`]. 27 #[repr(transparent)] 28 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 29 pub struct SpliceFlags: c::c_uint { 30 /// `SPLICE_F_MOVE` 31 const MOVE = linux_raw_sys::general::SPLICE_F_MOVE; 32 /// `SPLICE_F_NONBLOCK` 33 const NONBLOCK = linux_raw_sys::general::SPLICE_F_NONBLOCK; 34 /// `SPLICE_F_MORE` 35 const MORE = linux_raw_sys::general::SPLICE_F_MORE; 36 /// `SPLICE_F_GIFT` 37 const GIFT = linux_raw_sys::general::SPLICE_F_GIFT; 38 39 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 40 const _ = !0; 41 } 42 } 43 44 /// A buffer type for use with [`vmsplice`]. 45 /// 46 /// It is guaranteed to be ABI compatible with the iovec type on Unix platforms 47 /// and `WSABUF` on Windows. Unlike `IoSlice` and `IoSliceMut` it is 48 /// semantically like a raw pointer, and therefore can be shared or mutated as 49 /// needed. 50 /// 51 /// [`vmsplice`]: crate::pipe::vmsplice 52 #[repr(transparent)] 53 pub struct IoSliceRaw<'a> { 54 _buf: c::iovec, 55 _lifetime: PhantomData<&'a ()>, 56 } 57 58 impl<'a> IoSliceRaw<'a> { 59 /// Creates a new `IoSlice` wrapping a byte slice. from_slice(buf: &'a [u8]) -> Self60 pub fn from_slice(buf: &'a [u8]) -> Self { 61 IoSliceRaw { 62 _buf: c::iovec { 63 iov_base: (buf.as_ptr() as *mut u8).cast::<c::c_void>(), 64 iov_len: buf.len() as _, 65 }, 66 _lifetime: PhantomData, 67 } 68 } 69 70 /// Creates a new `IoSlice` wrapping a mutable byte slice. from_slice_mut(buf: &'a mut [u8]) -> Self71 pub fn from_slice_mut(buf: &'a mut [u8]) -> Self { 72 IoSliceRaw { 73 _buf: c::iovec { 74 iov_base: buf.as_mut_ptr().cast::<c::c_void>(), 75 iov_len: buf.len() as _, 76 }, 77 _lifetime: PhantomData, 78 } 79 } 80 } 81