mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-14 00:00:13 +02:00
Replace iovec with std::io::IoSlice
- Renames `bytes_vec` to `bytes_vectored` and `bytes_vec_mut` to `bytes_vectored_mut`.
This commit is contained in:
+11
-12
@@ -1,8 +1,7 @@
|
||||
use super::{IntoBuf, Take, Reader, FromBuf, Chain};
|
||||
use byteorder::{BigEndian, ByteOrder, LittleEndian};
|
||||
use iovec::IoVec;
|
||||
|
||||
use std::{cmp, ptr};
|
||||
use std::{cmp, io::IoSlice, ptr};
|
||||
|
||||
macro_rules! buf_get_impl {
|
||||
($this:ident, $size:expr, $conv:path) => ({
|
||||
@@ -119,14 +118,14 @@ pub trait Buf {
|
||||
/// Fills `dst` with potentially multiple slices starting at `self`'s
|
||||
/// current position.
|
||||
///
|
||||
/// If the `Buf` is backed by disjoint slices of bytes, `bytes_vec` enables
|
||||
/// fetching more than one slice at once. `dst` is a slice of `IoVec`
|
||||
/// If the `Buf` is backed by disjoint slices of bytes, `bytes_vectored` enables
|
||||
/// fetching more than one slice at once. `dst` is a slice of `IoSlice`
|
||||
/// references, enabling the slice to be directly used with [`writev`]
|
||||
/// without any further conversion. The sum of the lengths of all the
|
||||
/// buffers in `dst` will be less than or equal to `Buf::remaining()`.
|
||||
///
|
||||
/// The entries in `dst` will be overwritten, but the data **contained** by
|
||||
/// the slices **will not** be modified. If `bytes_vec` does not fill every
|
||||
/// the slices **will not** be modified. If `bytes_vectored` does not fill every
|
||||
/// entry in `dst`, then `dst` is guaranteed to contain all remaining slices
|
||||
/// in `self.
|
||||
///
|
||||
@@ -136,20 +135,20 @@ pub trait Buf {
|
||||
/// # Implementer notes
|
||||
///
|
||||
/// This function should never panic. Once the end of the buffer is reached,
|
||||
/// i.e., `Buf::remaining` returns 0, calls to `bytes_vec` must return 0
|
||||
/// i.e., `Buf::remaining` returns 0, calls to `bytes_vectored` must return 0
|
||||
/// without mutating `dst`.
|
||||
///
|
||||
/// Implementations should also take care to properly handle being called
|
||||
/// with `dst` being a zero length slice.
|
||||
///
|
||||
/// [`writev`]: http://man7.org/linux/man-pages/man2/readv.2.html
|
||||
fn bytes_vec<'a>(&'a self, dst: &mut [IoVec<'a>]) -> usize {
|
||||
fn bytes_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize {
|
||||
if dst.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if self.has_remaining() {
|
||||
dst[0] = self.bytes().into();
|
||||
dst[0] = IoSlice::new(self.bytes());
|
||||
1
|
||||
} else {
|
||||
0
|
||||
@@ -926,8 +925,8 @@ impl<'a, T: Buf + ?Sized> Buf for &'a mut T {
|
||||
(**self).bytes()
|
||||
}
|
||||
|
||||
fn bytes_vec<'b>(&'b self, dst: &mut [IoVec<'b>]) -> usize {
|
||||
(**self).bytes_vec(dst)
|
||||
fn bytes_vectored<'b>(&'b self, dst: &mut [IoSlice<'b>]) -> usize {
|
||||
(**self).bytes_vectored(dst)
|
||||
}
|
||||
|
||||
fn advance(&mut self, cnt: usize) {
|
||||
@@ -944,8 +943,8 @@ impl<T: Buf + ?Sized> Buf for Box<T> {
|
||||
(**self).bytes()
|
||||
}
|
||||
|
||||
fn bytes_vec<'b>(&'b self, dst: &mut [IoVec<'b>]) -> usize {
|
||||
(**self).bytes_vec(dst)
|
||||
fn bytes_vectored<'b>(&'b self, dst: &mut [IoSlice<'b>]) -> usize {
|
||||
(**self).bytes_vectored(dst)
|
||||
}
|
||||
|
||||
fn advance(&mut self, cnt: usize) {
|
||||
|
||||
+11
-12
@@ -1,8 +1,7 @@
|
||||
use super::{IntoBuf, Writer};
|
||||
use byteorder::{LittleEndian, ByteOrder, BigEndian};
|
||||
use iovec::IoVecMut;
|
||||
|
||||
use std::{cmp, ptr, usize};
|
||||
use std::{cmp, io::IoSliceMut, ptr, usize};
|
||||
|
||||
/// A trait for values that provide sequential write access to bytes.
|
||||
///
|
||||
@@ -162,15 +161,15 @@ pub trait BufMut {
|
||||
/// Fills `dst` with potentially multiple mutable slices starting at `self`'s
|
||||
/// current position.
|
||||
///
|
||||
/// If the `BufMut` is backed by disjoint slices of bytes, `bytes_vec_mut`
|
||||
/// If the `BufMut` is backed by disjoint slices of bytes, `bytes_vectored_mut`
|
||||
/// enables fetching more than one slice at once. `dst` is a slice of
|
||||
/// mutable `IoVec` references, enabling the slice to be directly used with
|
||||
/// mutable `IoSliceMut` references, enabling the slice to be directly used with
|
||||
/// [`readv`] without any further conversion. The sum of the lengths of all
|
||||
/// the buffers in `dst` will be less than or equal to
|
||||
/// `Buf::remaining_mut()`.
|
||||
///
|
||||
/// The entries in `dst` will be overwritten, but the data **contained** by
|
||||
/// the slices **will not** be modified. If `bytes_vec_mut` does not fill every
|
||||
/// the slices **will not** be modified. If `bytes_vectored_mut` does not fill every
|
||||
/// entry in `dst`, then `dst` is guaranteed to contain all remaining slices
|
||||
/// in `self.
|
||||
///
|
||||
@@ -180,20 +179,20 @@ pub trait BufMut {
|
||||
/// # Implementer notes
|
||||
///
|
||||
/// This function should never panic. Once the end of the buffer is reached,
|
||||
/// i.e., `BufMut::remaining_mut` returns 0, calls to `bytes_vec_mut` must
|
||||
/// i.e., `BufMut::remaining_mut` returns 0, calls to `bytes_vectored_mut` must
|
||||
/// return 0 without mutating `dst`.
|
||||
///
|
||||
/// Implementations should also take care to properly handle being called
|
||||
/// with `dst` being a zero length slice.
|
||||
///
|
||||
/// [`readv`]: http://man7.org/linux/man-pages/man2/readv.2.html
|
||||
unsafe fn bytes_vec_mut<'a>(&'a mut self, dst: &mut [IoVecMut<'a>]) -> usize {
|
||||
unsafe fn bytes_vectored_mut<'a>(&'a mut self, dst: &mut [IoSliceMut<'a>]) -> usize {
|
||||
if dst.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if self.has_remaining_mut() {
|
||||
dst[0] = self.bytes_mut().into();
|
||||
dst[0] = IoSliceMut::new(self.bytes_mut());
|
||||
1
|
||||
} else {
|
||||
0
|
||||
@@ -989,8 +988,8 @@ impl<'a, T: BufMut + ?Sized> BufMut for &'a mut T {
|
||||
(**self).bytes_mut()
|
||||
}
|
||||
|
||||
unsafe fn bytes_vec_mut<'b>(&'b mut self, dst: &mut [IoVecMut<'b>]) -> usize {
|
||||
(**self).bytes_vec_mut(dst)
|
||||
unsafe fn bytes_vectored_mut<'b>(&'b mut self, dst: &mut [IoSliceMut<'b>]) -> usize {
|
||||
(**self).bytes_vectored_mut(dst)
|
||||
}
|
||||
|
||||
unsafe fn advance_mut(&mut self, cnt: usize) {
|
||||
@@ -1007,8 +1006,8 @@ impl<T: BufMut + ?Sized> BufMut for Box<T> {
|
||||
(**self).bytes_mut()
|
||||
}
|
||||
|
||||
unsafe fn bytes_vec_mut<'b>(&'b mut self, dst: &mut [IoVecMut<'b>]) -> usize {
|
||||
(**self).bytes_vec_mut(dst)
|
||||
unsafe fn bytes_vectored_mut<'b>(&'b mut self, dst: &mut [IoSliceMut<'b>]) -> usize {
|
||||
(**self).bytes_vectored_mut(dst)
|
||||
}
|
||||
|
||||
unsafe fn advance_mut(&mut self, cnt: usize) {
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
use {Buf, BufMut};
|
||||
use buf::IntoIter;
|
||||
use iovec::{IoVec, IoVecMut};
|
||||
use std::io::{IoSlice, IoSliceMut};
|
||||
|
||||
/// A `Chain` sequences two buffers.
|
||||
///
|
||||
@@ -178,9 +178,9 @@ impl<T, U> Buf for Chain<T, U>
|
||||
self.b.advance(cnt);
|
||||
}
|
||||
|
||||
fn bytes_vec<'a>(&'a self, dst: &mut [IoVec<'a>]) -> usize {
|
||||
let mut n = self.a.bytes_vec(dst);
|
||||
n += self.b.bytes_vec(&mut dst[n..]);
|
||||
fn bytes_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize {
|
||||
let mut n = self.a.bytes_vectored(dst);
|
||||
n += self.b.bytes_vectored(&mut dst[n..]);
|
||||
n
|
||||
}
|
||||
}
|
||||
@@ -219,9 +219,9 @@ impl<T, U> BufMut for Chain<T, U>
|
||||
self.b.advance_mut(cnt);
|
||||
}
|
||||
|
||||
unsafe fn bytes_vec_mut<'a>(&'a mut self, dst: &mut [IoVecMut<'a>]) -> usize {
|
||||
let mut n = self.a.bytes_vec_mut(dst);
|
||||
n += self.b.bytes_vec_mut(&mut dst[n..]);
|
||||
unsafe fn bytes_vectored_mut<'a>(&'a mut self, dst: &mut [IoSliceMut<'a>]) -> usize {
|
||||
let mut n = self.a.bytes_vectored_mut(dst);
|
||||
n += self.b.bytes_vectored_mut(&mut dst[n..]);
|
||||
n
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -4,7 +4,7 @@ use {Buf, BufMut};
|
||||
|
||||
use self::either::Either;
|
||||
use self::either::Either::*;
|
||||
use iovec::{IoVec, IoVecMut};
|
||||
use std::io::{IoSlice, IoSliceMut};
|
||||
|
||||
impl<L, R> Buf for Either<L, R>
|
||||
where
|
||||
@@ -25,10 +25,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn bytes_vec<'a>(&'a self, dst: &mut [IoVec<'a>]) -> usize {
|
||||
fn bytes_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize {
|
||||
match *self {
|
||||
Left(ref b) => b.bytes_vec(dst),
|
||||
Right(ref b) => b.bytes_vec(dst),
|
||||
Left(ref b) => b.bytes_vectored(dst),
|
||||
Right(ref b) => b.bytes_vectored(dst),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,10 +66,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn bytes_vec_mut<'a>(&'a mut self, dst: &mut [IoVecMut<'a>]) -> usize {
|
||||
unsafe fn bytes_vectored_mut<'a>(&'a mut self, dst: &mut [IoSliceMut<'a>]) -> usize {
|
||||
match *self {
|
||||
Left(ref mut b) => b.bytes_vec_mut(dst),
|
||||
Right(ref mut b) => b.bytes_vec_mut(dst),
|
||||
Left(ref mut b) => b.bytes_vectored_mut(dst),
|
||||
Right(ref mut b) => b.bytes_vectored_mut(dst),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@
|
||||
#![doc(html_root_url = "https://docs.rs/bytes/0.5.0")]
|
||||
|
||||
extern crate byteorder;
|
||||
extern crate iovec;
|
||||
|
||||
pub mod buf;
|
||||
pub use buf::{
|
||||
|
||||
Reference in New Issue
Block a user