diff --git a/ntex-bytes/Cargo.toml b/ntex-bytes/Cargo.toml index c3e11dd8..4d929bb6 100644 --- a/ntex-bytes/Cargo.toml +++ b/ntex-bytes/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-bytes" -version = "0.1.12" +version = "0.1.13" license = "MIT" authors = ["Nikolay Kim ", "Carl Lerche "] description = "Types and traits for working with bytes (bytes crate fork)" diff --git a/ntex-bytes/src/bytes.rs b/ntex-bytes/src/bytes.rs index bb3782ef..f0613dbc 100644 --- a/ntex-bytes/src/bytes.rs +++ b/ntex-bytes/src/bytes.rs @@ -950,60 +950,20 @@ impl From<&'static str> for Bytes { } } -impl FromIterator for BytesMut { - fn from_iter>(into_iter: T) -> Self { - let iter = into_iter.into_iter(); - let (min, maybe_max) = iter.size_hint(); - - let mut out = BytesMut::with_capacity(maybe_max.unwrap_or(min)); - for i in iter { - out.reserve(1); - out.put_u8(i); - } - - out - } -} - -impl FromIterator for BytesVec { - fn from_iter>(into_iter: T) -> Self { - let iter = into_iter.into_iter(); - let (min, maybe_max) = iter.size_hint(); - - let mut out = BytesVec::with_capacity(maybe_max.unwrap_or(min)); - for i in iter { - out.reserve(1); - out.put_u8(i); - } - - out - } -} - impl FromIterator for Bytes { fn from_iter>(into_iter: T) -> Self { BytesMut::from_iter(into_iter).freeze() } } -impl<'a> FromIterator<&'a u8> for BytesMut { - fn from_iter>(into_iter: T) -> Self { - into_iter.into_iter().copied().collect::() - } -} - -impl<'a> FromIterator<&'a u8> for BytesVec { - fn from_iter>(into_iter: T) -> Self { - into_iter.into_iter().copied().collect::() - } -} - impl<'a> FromIterator<&'a u8> for Bytes { fn from_iter>(into_iter: T) -> Self { BytesMut::from_iter(into_iter).freeze() } } +impl Eq for Bytes {} + impl PartialEq for Bytes { fn eq(&self, other: &Bytes) -> bool { self.inner.as_ref() == other.inner.as_ref() @@ -1022,8 +982,6 @@ impl Ord for Bytes { } } -impl Eq for Bytes {} - impl Default for Bytes { #[inline] fn default() -> Bytes { @@ -1228,7 +1186,7 @@ impl BytesMut { /// use ntex_bytes::BytesMut; /// /// let b = BytesMut::with_capacity(64); - /// assert_eq!(b.capacity(), 96); + /// assert_eq!(b.capacity(), 64); /// ``` #[inline] pub fn capacity(&self) -> usize { @@ -1323,7 +1281,7 @@ impl BytesMut { /// let other = buf.split(); /// /// assert!(buf.is_empty()); - /// assert_eq!(1045, buf.capacity()); + /// assert_eq!(1013, buf.capacity()); /// /// assert_eq!(other, b"hello world"[..]); /// ``` @@ -1515,12 +1473,12 @@ impl BytesMut { /// let other = buf.split(); /// /// assert!(buf.is_empty()); - /// assert_eq!(buf.capacity(), 96); + /// assert_eq!(buf.capacity(), 64); /// /// drop(other); /// buf.reserve(128); /// - /// assert_eq!(buf.capacity(), 160); + /// assert_eq!(buf.capacity(), 128); /// assert_eq!(buf.as_ptr(), ptr); /// ``` /// @@ -1671,6 +1629,13 @@ impl AsRef<[u8]> for BytesMut { } } +impl AsMut<[u8]> for BytesMut { + #[inline] + fn as_mut(&mut self) -> &mut [u8] { + self.inner.as_mut() + } +} + impl Deref for BytesMut { type Target = [u8]; @@ -1680,13 +1645,6 @@ impl Deref for BytesMut { } } -impl AsMut<[u8]> for BytesMut { - #[inline] - fn as_mut(&mut self) -> &mut [u8] { - self.inner.as_mut() - } -} - impl DerefMut for BytesMut { #[inline] fn deref_mut(&mut self) -> &mut [u8] { @@ -1740,6 +1698,8 @@ impl From for BytesMut { } } +impl Eq for BytesMut {} + impl PartialEq for BytesMut { #[inline] fn eq(&self, other: &BytesMut) -> bool { @@ -1747,22 +1707,6 @@ impl PartialEq for BytesMut { } } -impl PartialOrd for BytesMut { - #[inline] - fn partial_cmp(&self, other: &BytesMut) -> Option { - self.inner.as_ref().partial_cmp(other.inner.as_ref()) - } -} - -impl Ord for BytesMut { - #[inline] - fn cmp(&self, other: &BytesMut) -> cmp::Ordering { - self.inner.as_ref().cmp(other.inner.as_ref()) - } -} - -impl Eq for BytesMut {} - impl Default for BytesMut { #[inline] fn default() -> BytesMut { @@ -1770,23 +1714,6 @@ impl Default for BytesMut { } } -impl fmt::Debug for BytesMut { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&debug::BsDebug(self.inner.as_ref()), fmt) - } -} - -impl hash::Hash for BytesMut { - #[inline] - fn hash(&self, state: &mut H) - where - H: hash::Hasher, - { - let s: &[u8] = self.as_ref(); - s.hash(state); - } -} - impl Borrow<[u8]> for BytesMut { #[inline] fn borrow(&self) -> &[u8] { @@ -1801,6 +1728,12 @@ impl BorrowMut<[u8]> for BytesMut { } } +impl fmt::Debug for BytesMut { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&debug::BsDebug(self.inner.as_ref()), fmt) + } +} + impl fmt::Write for BytesMut { #[inline] fn write_str(&mut self, s: &str) -> fmt::Result { @@ -1845,6 +1778,27 @@ impl<'a> IntoIterator for &'a BytesMut { } } +impl FromIterator for BytesMut { + fn from_iter>(into_iter: T) -> Self { + let iter = into_iter.into_iter(); + let (min, maybe_max) = iter.size_hint(); + + let mut out = BytesMut::with_capacity(maybe_max.unwrap_or(min)); + for i in iter { + out.reserve(1); + out.put_u8(i); + } + + out + } +} + +impl<'a> FromIterator<&'a u8> for BytesMut { + fn from_iter>(into_iter: T) -> Self { + into_iter.into_iter().copied().collect::() + } +} + impl Extend for BytesMut { fn extend(&mut self, iter: T) where @@ -2015,7 +1969,7 @@ impl BytesVec { /// use ntex_bytes::BytesVec; /// /// let b = BytesVec::with_capacity(64); - /// assert_eq!(b.capacity(), 96); + /// assert_eq!(b.capacity(), 64); /// ``` #[inline] pub fn capacity(&self) -> usize { @@ -2074,7 +2028,7 @@ impl BytesVec { /// let other = buf.split(); /// /// assert!(buf.is_empty()); - /// assert_eq!(1045, buf.capacity()); + /// assert_eq!(1013, buf.capacity()); /// /// assert_eq!(other, b"hello world"[..]); /// ``` @@ -2264,12 +2218,12 @@ impl BytesVec { /// let other = buf.split(); /// /// assert!(buf.is_empty()); - /// assert_eq!(buf.capacity(), 96); + /// assert_eq!(buf.capacity(), 64); /// /// drop(other); /// buf.reserve(128); /// - /// assert_eq!(buf.capacity(), 160); + /// assert_eq!(buf.capacity(), 128); /// assert_eq!(buf.as_ptr(), ptr); /// ``` /// @@ -2461,20 +2415,6 @@ impl PartialEq for BytesVec { } } -impl Ord for BytesVec { - #[inline] - fn cmp(&self, other: &BytesVec) -> cmp::Ordering { - self.inner.as_ref().cmp(other.inner.as_ref()) - } -} - -impl PartialOrd for BytesVec { - #[inline] - fn partial_cmp(&self, other: &BytesVec) -> Option { - self.inner.as_ref().partial_cmp(other.inner.as_ref()) - } -} - impl Default for BytesVec { #[inline] fn default() -> BytesVec { @@ -2482,23 +2422,6 @@ impl Default for BytesVec { } } -impl fmt::Debug for BytesVec { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&debug::BsDebug(self.inner.as_ref()), fmt) - } -} - -impl hash::Hash for BytesVec { - #[inline] - fn hash(&self, state: &mut H) - where - H: hash::Hasher, - { - let s: &[u8] = self.as_ref(); - s.hash(state); - } -} - impl Borrow<[u8]> for BytesVec { #[inline] fn borrow(&self) -> &[u8] { @@ -2513,6 +2436,12 @@ impl BorrowMut<[u8]> for BytesVec { } } +impl fmt::Debug for BytesVec { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&debug::BsDebug(self.inner.as_ref()), fmt) + } +} + impl fmt::Write for BytesVec { #[inline] fn write_str(&mut self, s: &str) -> fmt::Result { @@ -2548,6 +2477,27 @@ impl<'a> IntoIterator for &'a BytesVec { } } +impl FromIterator for BytesVec { + fn from_iter>(into_iter: T) -> Self { + let iter = into_iter.into_iter(); + let (min, maybe_max) = iter.size_hint(); + + let mut out = BytesVec::with_capacity(maybe_max.unwrap_or(min)); + for i in iter { + out.reserve(1); + out.put_u8(i); + } + + out + } +} + +impl<'a> FromIterator<&'a u8> for BytesVec { + fn from_iter>(into_iter: T) -> Self { + into_iter.into_iter().copied().collect::() + } +} + impl Extend for BytesVec { fn extend(&mut self, iter: T) where @@ -2583,9 +2533,12 @@ impl InnerVec { #[inline] fn from_slice(cap: usize, src: &[u8], pool: PoolRef) -> InnerVec { - // TODO: vec must be aligned to SharedVec instead of u8 - let mut vec = Vec::::with_capacity((cap / SHARED_VEC_SIZE) + 2); - #[allow(clippy::uninit_vec)] + // vec must be aligned to SharedVec instead of u8 + let mut vec_cap = (cap / SHARED_VEC_SIZE) + 1; + if cap % SHARED_VEC_SIZE != 0 { + vec_cap += 1; + } + let mut vec = Vec::::with_capacity(vec_cap); unsafe { // Store data in vec let len = src.len() as u32; @@ -2961,9 +2914,12 @@ impl Inner { #[inline] fn from_slice(cap: usize, src: &[u8], pool: PoolRef) -> Inner { - // TODO: vec must be aligned to SharedVec instead of u8 - let mut vec = Vec::::with_capacity((cap / SHARED_VEC_SIZE) + 2); - #[allow(clippy::uninit_vec)] + // vec must be aligned to SharedVec instead of u8 + let mut vec_cap = (cap / SHARED_VEC_SIZE) + 1; + if cap % SHARED_VEC_SIZE != 0 { + vec_cap += 1; + } + let mut vec = Vec::::with_capacity(vec_cap); unsafe { // Store data in vec let len = src.len(); @@ -3692,12 +3648,6 @@ impl PartialEq<[u8]> for BytesMut { } } -impl PartialOrd<[u8]> for BytesMut { - fn partial_cmp(&self, other: &[u8]) -> Option { - (**self).partial_cmp(other) - } -} - impl PartialEq for [u8] { fn eq(&self, other: &BytesMut) -> bool { *other == *self @@ -3716,72 +3666,36 @@ impl PartialEq for BytesMut { } } -impl PartialOrd for BytesMut { - fn partial_cmp(&self, other: &str) -> Option { - (**self).partial_cmp(other.as_bytes()) - } -} - impl PartialEq for str { fn eq(&self, other: &BytesMut) -> bool { *other == *self } } -impl PartialOrd for str { - fn partial_cmp(&self, other: &BytesMut) -> Option { - other.partial_cmp(self) - } -} - impl PartialEq> for BytesMut { fn eq(&self, other: &Vec) -> bool { *self == other[..] } } -impl PartialOrd> for BytesMut { - fn partial_cmp(&self, other: &Vec) -> Option { - (**self).partial_cmp(&other[..]) - } -} - impl PartialEq for Vec { fn eq(&self, other: &BytesMut) -> bool { *other == *self } } -impl PartialOrd for Vec { - fn partial_cmp(&self, other: &BytesMut) -> Option { - other.partial_cmp(self) - } -} - impl PartialEq for BytesMut { fn eq(&self, other: &String) -> bool { *self == other[..] } } -impl PartialOrd for BytesMut { - fn partial_cmp(&self, other: &String) -> Option { - (**self).partial_cmp(other.as_bytes()) - } -} - impl PartialEq for String { fn eq(&self, other: &BytesMut) -> bool { *other == *self } } -impl PartialOrd for String { - fn partial_cmp(&self, other: &BytesMut) -> Option { - other.partial_cmp(self) - } -} - impl<'a, T: ?Sized> PartialEq<&'a T> for BytesMut where BytesMut: PartialEq, @@ -3791,39 +3705,18 @@ where } } -impl<'a, T: ?Sized> PartialOrd<&'a T> for BytesMut -where - BytesMut: PartialOrd, -{ - fn partial_cmp(&self, other: &&'a T) -> Option { - self.partial_cmp(*other) - } -} - impl PartialEq for &[u8] { fn eq(&self, other: &BytesMut) -> bool { *other == *self } } -impl PartialOrd for &[u8] { - fn partial_cmp(&self, other: &BytesMut) -> Option { - other.partial_cmp(self) - } -} - impl PartialEq for &str { fn eq(&self, other: &BytesMut) -> bool { *other == *self } } -impl PartialOrd for &str { - fn partial_cmp(&self, other: &BytesMut) -> Option { - other.partial_cmp(self) - } -} - impl PartialEq<[u8]> for Bytes { fn eq(&self, other: &[u8]) -> bool { self.inner.as_ref() == other @@ -4016,84 +3909,42 @@ impl PartialEq for [u8] { } } -impl PartialOrd for [u8] { - fn partial_cmp(&self, other: &BytesVec) -> Option { - other.partial_cmp(self) - } -} - impl PartialEq for BytesVec { fn eq(&self, other: &str) -> bool { &**self == other.as_bytes() } } -impl PartialOrd for BytesVec { - fn partial_cmp(&self, other: &str) -> Option { - (**self).partial_cmp(other.as_bytes()) - } -} - impl PartialEq for str { fn eq(&self, other: &BytesVec) -> bool { *other == *self } } -impl PartialOrd for str { - fn partial_cmp(&self, other: &BytesVec) -> Option { - other.partial_cmp(self) - } -} - impl PartialEq> for BytesVec { fn eq(&self, other: &Vec) -> bool { *self == other[..] } } -impl PartialOrd> for BytesVec { - fn partial_cmp(&self, other: &Vec) -> Option { - (**self).partial_cmp(&other[..]) - } -} - impl PartialEq for Vec { fn eq(&self, other: &BytesVec) -> bool { *other == *self } } -impl PartialOrd for Vec { - fn partial_cmp(&self, other: &BytesVec) -> Option { - other.partial_cmp(self) - } -} - impl PartialEq for BytesVec { fn eq(&self, other: &String) -> bool { *self == other[..] } } -impl PartialOrd for BytesVec { - fn partial_cmp(&self, other: &String) -> Option { - (**self).partial_cmp(other.as_bytes()) - } -} - impl PartialEq for String { fn eq(&self, other: &BytesVec) -> bool { *other == *self } } -impl PartialOrd for String { - fn partial_cmp(&self, other: &BytesVec) -> Option { - other.partial_cmp(self) - } -} - impl<'a, T: ?Sized> PartialEq<&'a T> for BytesVec where BytesVec: PartialEq, @@ -4103,39 +3954,18 @@ where } } -impl<'a, T: ?Sized> PartialOrd<&'a T> for BytesVec -where - BytesVec: PartialOrd, -{ - fn partial_cmp(&self, other: &&'a T) -> Option { - self.partial_cmp(*other) - } -} - impl PartialEq for &[u8] { fn eq(&self, other: &BytesVec) -> bool { *other == *self } } -impl PartialOrd for &[u8] { - fn partial_cmp(&self, other: &BytesVec) -> Option { - other.partial_cmp(self) - } -} - impl PartialEq for &str { fn eq(&self, other: &BytesVec) -> bool { *other == *self } } -impl PartialOrd for &str { - fn partial_cmp(&self, other: &BytesVec) -> Option { - other.partial_cmp(self) - } -} - // While there is `std::process:abort`, it's only available in Rust 1.17, and // our minimum supported version is currently 1.15. So, this acts as an abort // by triggering a double panic, which always aborts in Rust. diff --git a/ntex-bytes/src/lib.rs b/ntex-bytes/src/lib.rs index c40c2693..8fae576f 100644 --- a/ntex-bytes/src/lib.rs +++ b/ntex-bytes/src/lib.rs @@ -39,7 +39,7 @@ //! let b = buf.split(); //! assert_eq!(b, b"goodbye world"[..]); //! -//! assert_eq!(buf.capacity(), 1030); +//! assert_eq!(buf.capacity(), 998); //! ``` //! //! In the above example, only a single buffer of 1024 is allocated. The handles diff --git a/ntex-bytes/src/pool.rs b/ntex-bytes/src/pool.rs index e53034da..eb83337b 100644 --- a/ntex-bytes/src/pool.rs +++ b/ntex-bytes/src/pool.rs @@ -16,7 +16,7 @@ pub struct Pool { #[derive(Copy, Clone)] pub struct PoolRef(&'static MemoryPool); -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)] pub struct PoolId(u8); #[derive(Copy, Clone)] @@ -504,21 +504,6 @@ impl Pool { true } - #[inline] - #[doc(hidden)] - #[deprecated] - /// Check if pool is pedning - pub fn is_pending(&self) -> bool { - !self.is_ready() - } - - #[doc(hidden)] - #[inline] - /// Check if pool is pedning - pub fn windows(&self) -> [(usize, usize); 10] { - self.inner.windows.get() - } - #[inline] /// Get `PoolRef` instance for this pool. pub fn pool_ref(&self) -> PoolRef { diff --git a/ntex-bytes/tests/test_bytes.rs b/ntex-bytes/tests/test_bytes.rs index 1f7e1bb0..8a53b627 100644 --- a/ntex-bytes/tests/test_bytes.rs +++ b/ntex-bytes/tests/test_bytes.rs @@ -1,7 +1,6 @@ -#![deny(warnings, rust_2018_idioms)] -use std::task::Poll; +use std::{borrow::Borrow, borrow::BorrowMut, task::Poll}; -use ntex_bytes::{Buf, BufMut, Bytes, BytesMut, BytesVec, PoolId}; +use ntex_bytes::{Buf, BufMut, Bytes, BytesMut, BytesVec, Pool, PoolId, PoolRef}; const LONG: &[u8] = b"mary had a little lamb, little lamb, little lamb"; const SHORT: &[u8] = b"hello world"; @@ -263,7 +262,7 @@ fn split_off_uninitialized() { assert_eq!(bytes.capacity(), 128); assert_eq!(other.len(), 0); - assert_eq!(other.capacity(), 928); + assert_eq!(other.capacity(), 896); } #[test] @@ -441,6 +440,7 @@ fn split_off_to_at_gt_len() { fn fns_defined_for_bytes() { let mut bytes = Bytes::from(&b"hello world"[..]); bytes.as_ptr(); + assert_eq!(Borrow::<[u8]>::borrow(&bytes), b"hello world"); assert!(bytes > "g"); assert!(bytes > "g".to_string()); @@ -465,6 +465,12 @@ fn fns_defined_for_bytes() { let v: Vec = bytes.as_ref().iter().cloned().collect(); assert_eq!(&v[..], bytes); + let v: Vec = bytes.clone().into_iter().collect(); + assert_eq!(&v[..], bytes); + + let v: Vec = bytes.as_ref().into_iter().cloned().collect(); + assert_eq!(&v[..], bytes); + let b2: Bytes = v.iter().collect(); assert_eq!(b2, bytes); assert_eq!(&v[..], b2); @@ -481,15 +487,8 @@ fn fns_defined_for_bytes_mut() { let mut bytes = BytesMut::from(&b"hello world"[..]); bytes.as_ptr(); bytes.as_mut_ptr(); - - assert!(bytes > "g"); - assert!(bytes > "g".to_string()); - assert!(bytes > "g".as_bytes().to_vec()); - assert!(bytes > BytesMut::from(&"g"[..])); - assert!("g" > bytes); - assert!("g".to_string() > bytes); - assert!("g".as_bytes().to_vec() > bytes); - assert!(BytesMut::from(&"g"[..]) < bytes); + assert_eq!(Borrow::<[u8]>::borrow(&bytes), b"hello world"); + assert_eq!(BorrowMut::<[u8]>::borrow_mut(&mut bytes), b"hello world"); assert_eq!(bytes, "hello world"); assert_eq!(bytes, "hello world".as_bytes().to_vec()); @@ -542,15 +541,8 @@ fn fns_defined_for_bytes_vec() { let mut bytes = BytesVec::copy_from_slice(&b"hello world"[..]); bytes.as_ptr(); bytes.as_mut_ptr(); - - assert!(bytes > "g"); - assert!(bytes > "g".to_string()); - assert!(bytes > "g".as_bytes().to_vec()); - assert!(bytes > BytesVec::copy_from_slice("g")); - assert!("g" > bytes); - assert!("g".to_string() > bytes); - assert!("g".as_bytes().to_vec() > bytes); - assert!(BytesVec::copy_from_slice(&"g"[..]) < bytes); + assert_eq!(Borrow::<[u8]>::borrow(&bytes), b"hello world"); + assert_eq!(BorrowMut::<[u8]>::borrow_mut(&mut bytes), b"hello world"); assert_eq!(bytes, "hello world"); assert_eq!(bytes, "hello world".as_bytes().to_vec()); @@ -569,6 +561,9 @@ fn fns_defined_for_bytes_vec() { let v: Vec = bytes.iter().cloned().collect(); assert_eq!(&v[..], bytes); + let v: Vec = bytes.as_ref().into_iter().cloned().collect(); + assert_eq!(&v[..], bytes); + let v: Vec = bytes.into_iter().collect(); let mut bytes = BytesVec::copy_from_slice(b"hello world"); @@ -956,13 +951,19 @@ fn bytes_vec() { #[test] fn pool() { + assert_eq!(PoolRef::default().id(), PoolId::DEFAULT); + assert!(format!("{:?}", PoolRef::default()).contains("PoolRef")); + + assert_eq!(Pool::from(PoolRef::default()).id(), PoolId::DEFAULT); + assert!(format!("{:?}", Pool::from(PoolId::DEFAULT)).contains("Pool")); + // Pool let p1 = PoolId::P1.pool_ref(); assert_eq!(p1.allocated(), 0); let mut buf = BytesMut::with_capacity_in(1024, p1); - assert_eq!(p1.allocated(), 1056 + shared_vec()); + assert_eq!(p1.allocated(), 1024 + shared_vec()); buf.reserve(2048); - assert_eq!(p1.allocated(), 2080 + shared_vec()); + assert_eq!(p1.allocated(), 2048 + shared_vec()); drop(buf); assert_eq!(p1.allocated(), 0); @@ -970,26 +971,43 @@ fn pool() { let p = PoolId::DEFAULT.pool_ref(); assert_eq!(p.allocated(), 0); let mut buf = BytesMut::with_capacity(1024); - assert_eq!(p.allocated(), 1056 + shared_vec()); + assert_eq!(p.allocated(), 1024 + shared_vec()); buf.reserve(2048); - assert_eq!(p.allocated(), 2080 + shared_vec()); + assert_eq!(p.allocated(), 2048 + shared_vec()); drop(buf); assert_eq!(p.allocated(), 0); let mut buf = BytesMut::with_capacity(1024); - assert_eq!(p.allocated(), 1056 + shared_vec()); + assert_eq!(p.allocated(), 1024 + shared_vec()); assert_eq!(p1.allocated(), 0); p1.move_in(&mut buf); assert_eq!(p.allocated(), 0); - assert_eq!(p1.allocated(), 1056 + shared_vec()); + assert_eq!(p1.allocated(), 1024 + shared_vec()); + + let mut buf = BytesMut::from(Vec::with_capacity(1024)); + assert_eq!(p.allocated(), 992 + shared_vec()); + assert_eq!(p1.allocated(), 1056); + p1.move_in(&mut buf); + assert_eq!(p.allocated(), 0); + assert_eq!(p1.allocated(), 2048 + shared_vec()); let p1 = PoolId::P2.pool_ref(); let mut buf = BytesVec::with_capacity(1024); - assert_eq!(p.allocated(), 1056 + shared_vec()); + assert_eq!(p.allocated(), 1024 + shared_vec()); assert_eq!(p1.allocated(), 0); p1.move_vec_in(&mut buf); assert_eq!(p.allocated(), 0); - assert_eq!(p1.allocated(), 1056 + shared_vec()); + assert_eq!(p1.allocated(), 1024 + shared_vec()); + + let p3 = PoolId::P3.pool_ref(); + assert_eq!(p3.id(), PoolId::P3); + let b: BytesMut = p3.buf_with_capacity(1024); + assert_eq!(b.capacity(), 992 + shared_vec()); + assert_eq!(p3.allocated(), 1024 + shared_vec()); + + let b: BytesVec = p3.vec_with_capacity(1024); + assert_eq!(b.capacity(), 992 + shared_vec()); + assert_eq!(p3.allocated(), 2080 + shared_vec()); } #[ntex::test] diff --git a/ntex/tests/connect.rs b/ntex/tests/connect.rs index ffa47656..cc7465e0 100644 --- a/ntex/tests/connect.rs +++ b/ntex/tests/connect.rs @@ -4,7 +4,7 @@ use ntex::codec::BytesCodec; use ntex::connect::Connect; use ntex::io::{types::PeerAddr, Io}; use ntex::service::{fn_service, pipeline_factory, Service, ServiceFactory}; -use ntex::{server::test_server, util::Bytes}; +use ntex::{server::test_server, time, util::Bytes}; #[cfg(feature = "openssl")] fn ssl_acceptor() -> tls_openssl::ssl::SslAcceptor { @@ -131,6 +131,7 @@ async fn test_openssl_read_before_error() { io.send(Bytes::from_static(b"test"), &BytesCodec) .await .unwrap(); + time::sleep(time::Millis(100)).await; Ok::<_, Box>(()) })) }); @@ -216,6 +217,7 @@ async fn test_static_str() { io.send(Bytes::from_static(b"test"), &BytesCodec) .await .unwrap(); + time::sleep(time::Millis(100)).await; Ok::<_, io::Error>(()) }) });