diff options
| author | Thomas de Zeeuw <thomasdezeeuw@gmail.com> | 2019-07-25 22:30:52 +0200 | 
|---|---|---|
| committer | Thomas de Zeeuw <thomasdezeeuw@gmail.com> | 2019-08-03 10:44:45 +0200 | 
| commit | dad56c39474377c7d47e261b380d0be3aed104cc (patch) | |
| tree | 52b4ad99a6f344fe292a0b0b6b38c6089eee8ad6 /src/libstd/sys/unix/io.rs | |
| parent | d7270712cb446aad0817040bbca73a8d024f67b0 (diff) | |
| download | rust-dad56c39474377c7d47e261b380d0be3aed104cc.tar.gz rust-dad56c39474377c7d47e261b380d0be3aed104cc.zip | |
Add {IoSlice, IoSliceMut}::advance
Diffstat (limited to 'src/libstd/sys/unix/io.rs')
| -rw-r--r-- | src/libstd/sys/unix/io.rs | 24 | 
1 files changed, 24 insertions, 0 deletions
| diff --git a/src/libstd/sys/unix/io.rs b/src/libstd/sys/unix/io.rs index bc854e772e1..a3a72919176 100644 --- a/src/libstd/sys/unix/io.rs +++ b/src/libstd/sys/unix/io.rs @@ -22,6 +22,18 @@ impl<'a> IoSlice<'a> { } #[inline] + pub fn advance(&mut self, n: usize) { + if self.vec.iov_len < n { + panic!("advancing IoSlice beyond its length"); + } + + unsafe { + self.vec.iov_len -= n; + self.vec.iov_base = self.vec.iov_base.add(n); + } + } + + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) @@ -48,6 +60,18 @@ impl<'a> IoSliceMut<'a> { } #[inline] + pub fn advance(&mut self, n: usize) { + if self.vec.iov_len < n { + panic!("advancing IoSliceMut beyond its length"); + } + + unsafe { + self.vec.iov_len -= n; + self.vec.iov_base = self.vec.iov_base.add(n); + } + } + + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) | 
