diff options
Diffstat (limited to 'src/buf/buf_mut.rs')
-rw-r--r-- | src/buf/buf_mut.rs | 138 |
1 files changed, 29 insertions, 109 deletions
diff --git a/src/buf/buf_mut.rs b/src/buf/buf_mut.rs index 7f3c1f7..29774b9 100644 --- a/src/buf/buf_mut.rs +++ b/src/buf/buf_mut.rs @@ -1,6 +1,6 @@ use super::{IntoBuf, Writer}; use byteorder::{LittleEndian, ByteOrder, BigEndian}; -use iovec::IoVec; +use iovec::IoVecMut; use std::{cmp, io, ptr, usize}; @@ -189,7 +189,7 @@ pub trait BufMut { /// 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 [&'a mut IoVec]) -> usize { + unsafe fn bytes_vec_mut<'a>(&'a mut self, dst: &mut [IoVecMut<'a>]) -> usize { if dst.is_empty() { return 0; } @@ -339,14 +339,6 @@ pub trait BufMut { self.put_slice(&src) } - #[doc(hidden)] - #[deprecated(note="use put_u16_be or put_u16_le")] - fn put_u16<T: ByteOrder>(&mut self, n: u16) where Self: Sized { - let mut buf = [0; 2]; - T::write_u16(&mut buf, n); - self.put_slice(&buf) - } - /// Writes an unsigned 16 bit integer to `self` in big-endian byte order. /// /// The current position is advanced by 2. @@ -357,7 +349,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_u16_be(0x0809); + /// buf.put_u16(0x0809); /// assert_eq!(buf, b"\x08\x09"); /// ``` /// @@ -365,7 +357,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_u16_be(&mut self, n: u16) { + fn put_u16(&mut self, n: u16) { let mut buf = [0; 2]; BigEndian::write_u16(&mut buf, n); self.put_slice(&buf) @@ -395,14 +387,6 @@ pub trait BufMut { self.put_slice(&buf) } - #[doc(hidden)] - #[deprecated(note="use put_i16_be or put_i16_le")] - fn put_i16<T: ByteOrder>(&mut self, n: i16) where Self: Sized { - let mut buf = [0; 2]; - T::write_i16(&mut buf, n); - self.put_slice(&buf) - } - /// Writes a signed 16 bit integer to `self` in big-endian byte order. /// /// The current position is advanced by 2. @@ -413,7 +397,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_i16_be(0x0809); + /// buf.put_i16(0x0809); /// assert_eq!(buf, b"\x08\x09"); /// ``` /// @@ -421,7 +405,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_i16_be(&mut self, n: i16) { + fn put_i16(&mut self, n: i16) { let mut buf = [0; 2]; BigEndian::write_i16(&mut buf, n); self.put_slice(&buf) @@ -451,14 +435,6 @@ pub trait BufMut { self.put_slice(&buf) } - #[doc(hidden)] - #[deprecated(note="use put_u32_be or put_u32_le")] - fn put_u32<T: ByteOrder>(&mut self, n: u32) where Self: Sized { - let mut buf = [0; 4]; - T::write_u32(&mut buf, n); - self.put_slice(&buf) - } - /// Writes an unsigned 32 bit integer to `self` in big-endian byte order. /// /// The current position is advanced by 4. @@ -469,7 +445,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_u32_be(0x0809A0A1); + /// buf.put_u32(0x0809A0A1); /// assert_eq!(buf, b"\x08\x09\xA0\xA1"); /// ``` /// @@ -477,7 +453,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_u32_be(&mut self, n: u32) { + fn put_u32(&mut self, n: u32) { let mut buf = [0; 4]; BigEndian::write_u32(&mut buf, n); self.put_slice(&buf) @@ -507,14 +483,6 @@ pub trait BufMut { self.put_slice(&buf) } - #[doc(hidden)] - #[deprecated(note="use put_i32_be or put_i32_le")] - fn put_i32<T: ByteOrder>(&mut self, n: i32) where Self: Sized { - let mut buf = [0; 4]; - T::write_i32(&mut buf, n); - self.put_slice(&buf) - } - /// Writes a signed 32 bit integer to `self` in big-endian byte order. /// /// The current position is advanced by 4. @@ -525,7 +493,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_i32_be(0x0809A0A1); + /// buf.put_i32(0x0809A0A1); /// assert_eq!(buf, b"\x08\x09\xA0\xA1"); /// ``` /// @@ -533,7 +501,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_i32_be(&mut self, n: i32) { + fn put_i32(&mut self, n: i32) { let mut buf = [0; 4]; BigEndian::write_i32(&mut buf, n); self.put_slice(&buf) @@ -563,14 +531,6 @@ pub trait BufMut { self.put_slice(&buf) } - #[doc(hidden)] - #[deprecated(note="use put_u64_be or put_u64_le")] - fn put_u64<T: ByteOrder>(&mut self, n: u64) where Self: Sized { - let mut buf = [0; 8]; - T::write_u64(&mut buf, n); - self.put_slice(&buf) - } - /// Writes an unsigned 64 bit integer to `self` in the big-endian byte order. /// /// The current position is advanced by 8. @@ -581,7 +541,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_u64_be(0x0102030405060708); + /// buf.put_u64(0x0102030405060708); /// assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08"); /// ``` /// @@ -589,7 +549,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_u64_be(&mut self, n: u64) { + fn put_u64(&mut self, n: u64) { let mut buf = [0; 8]; BigEndian::write_u64(&mut buf, n); self.put_slice(&buf) @@ -619,14 +579,6 @@ pub trait BufMut { self.put_slice(&buf) } - #[doc(hidden)] - #[deprecated(note="use put_i64_be or put_i64_le")] - fn put_i64<T: ByteOrder>(&mut self, n: i64) where Self: Sized { - let mut buf = [0; 8]; - T::write_i64(&mut buf, n); - self.put_slice(&buf) - } - /// Writes a signed 64 bit integer to `self` in the big-endian byte order. /// /// The current position is advanced by 8. @@ -637,7 +589,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_i64_be(0x0102030405060708); + /// buf.put_i64(0x0102030405060708); /// assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08"); /// ``` /// @@ -645,7 +597,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_i64_be(&mut self, n: i64) { + fn put_i64(&mut self, n: i64) { let mut buf = [0; 8]; BigEndian::write_i64(&mut buf, n); self.put_slice(&buf) @@ -686,7 +638,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_u128_be(0x01020304050607080910111213141516); + /// buf.put_u128(0x01020304050607080910111213141516); /// assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16"); /// ``` /// @@ -695,7 +647,7 @@ pub trait BufMut { /// This function panics if there is not enough remaining capacity in /// `self`. #[cfg(feature = "i128")] - fn put_u128_be(&mut self, n: u128) { + fn put_u128(&mut self, n: u128) { let mut buf = [0; 16]; BigEndian::write_u128(&mut buf, n); self.put_slice(&buf) @@ -738,7 +690,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_i128_be(0x01020304050607080910111213141516); + /// buf.put_i128(0x01020304050607080910111213141516); /// assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16"); /// ``` /// @@ -747,7 +699,7 @@ pub trait BufMut { /// This function panics if there is not enough remaining capacity in /// `self`. #[cfg(feature = "i128")] - fn put_i128_be(&mut self, n: i128) { + fn put_i128(&mut self, n: i128) { let mut buf = [0; 16]; BigEndian::write_i128(&mut buf, n); self.put_slice(&buf) @@ -779,14 +731,6 @@ pub trait BufMut { self.put_slice(&buf) } - #[doc(hidden)] - #[deprecated(note="use put_uint_be or put_uint_le")] - fn put_uint<T: ByteOrder>(&mut self, n: u64, nbytes: usize) where Self: Sized { - let mut buf = [0; 8]; - T::write_uint(&mut buf, n, nbytes); - self.put_slice(&buf[0..nbytes]) - } - /// Writes an unsigned n-byte integer to `self` in big-endian byte order. /// /// The current position is advanced by `nbytes`. @@ -797,7 +741,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_uint_be(0x010203, 3); + /// buf.put_uint(0x010203, 3); /// assert_eq!(buf, b"\x01\x02\x03"); /// ``` /// @@ -805,7 +749,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_uint_be(&mut self, n: u64, nbytes: usize) { + fn put_uint(&mut self, n: u64, nbytes: usize) { let mut buf = [0; 8]; BigEndian::write_uint(&mut buf, n, nbytes); self.put_slice(&buf[0..nbytes]) @@ -835,14 +779,6 @@ pub trait BufMut { self.put_slice(&buf[0..nbytes]) } - #[doc(hidden)] - #[deprecated(note="use put_int_be or put_int_le")] - fn put_int<T: ByteOrder>(&mut self, n: i64, nbytes: usize) where Self: Sized { - let mut buf = [0; 8]; - T::write_int(&mut buf, n, nbytes); - self.put_slice(&buf[0..nbytes]) - } - /// Writes a signed n-byte integer to `self` in big-endian byte order. /// /// The current position is advanced by `nbytes`. @@ -853,7 +789,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_int_be(0x010203, 3); + /// buf.put_int(0x010203, 3); /// assert_eq!(buf, b"\x01\x02\x03"); /// ``` /// @@ -861,7 +797,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_int_be(&mut self, n: i64, nbytes: usize) { + fn put_int(&mut self, n: i64, nbytes: usize) { let mut buf = [0; 8]; BigEndian::write_int(&mut buf, n, nbytes); self.put_slice(&buf[0..nbytes]) @@ -891,14 +827,6 @@ pub trait BufMut { self.put_slice(&buf[0..nbytes]) } - #[doc(hidden)] - #[deprecated(note="use put_f32_be or put_f32_le")] - fn put_f32<T: ByteOrder>(&mut self, n: f32) where Self: Sized { - let mut buf = [0; 4]; - T::write_f32(&mut buf, n); - self.put_slice(&buf) - } - /// Writes an IEEE754 single-precision (4 bytes) floating point number to /// `self` in big-endian byte order. /// @@ -910,7 +838,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_f32_be(1.2f32); + /// buf.put_f32(1.2f32); /// assert_eq!(buf, b"\x3F\x99\x99\x9A"); /// ``` /// @@ -918,7 +846,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_f32_be(&mut self, n: f32) { + fn put_f32(&mut self, n: f32) { let mut buf = [0; 4]; BigEndian::write_f32(&mut buf, n); self.put_slice(&buf) @@ -949,14 +877,6 @@ pub trait BufMut { self.put_slice(&buf) } - #[doc(hidden)] - #[deprecated(note="use put_f64_be or put_f64_le")] - fn put_f64<T: ByteOrder>(&mut self, n: f64) where Self: Sized { - let mut buf = [0; 8]; - T::write_f64(&mut buf, n); - self.put_slice(&buf) - } - /// Writes an IEEE754 double-precision (8 bytes) floating point number to /// `self` in big-endian byte order. /// @@ -968,7 +888,7 @@ pub trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_f64_be(1.2f64); + /// buf.put_f64(1.2f64); /// assert_eq!(buf, b"\x3F\xF3\x33\x33\x33\x33\x33\x33"); /// ``` /// @@ -976,7 +896,7 @@ pub trait BufMut { /// /// This function panics if there is not enough remaining capacity in /// `self`. - fn put_f64_be(&mut self, n: f64) { + fn put_f64(&mut self, n: f64) { let mut buf = [0; 8]; BigEndian::write_f64(&mut buf, n); self.put_slice(&buf) @@ -1072,7 +992,7 @@ impl<'a, T: BufMut + ?Sized> BufMut for &'a mut T { (**self).bytes_mut() } - unsafe fn bytes_vec_mut<'b>(&'b mut self, dst: &mut [&'b mut IoVec]) -> usize { + unsafe fn bytes_vec_mut<'b>(&'b mut self, dst: &mut [IoVecMut<'b>]) -> usize { (**self).bytes_vec_mut(dst) } @@ -1090,7 +1010,7 @@ impl<T: BufMut + ?Sized> BufMut for Box<T> { (**self).bytes_mut() } - unsafe fn bytes_vec_mut<'b>(&'b mut self, dst: &mut [&'b mut IoVec]) -> usize { + unsafe fn bytes_vec_mut<'b>(&'b mut self, dst: &mut [IoVecMut<'b>]) -> usize { (**self).bytes_vec_mut(dst) } @@ -1164,4 +1084,4 @@ impl BufMut for Vec<u8> { // The existance of this function makes the compiler catch if the BufMut // trait is "object-safe" or not. -fn _assert_trait_object(_b: &BufMut) {} +fn _assert_trait_object(_b: &dyn BufMut) {} |