mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-10 00:00:09 +02:00
Tweak Bytes helpers
This commit is contained in:
@@ -145,7 +145,7 @@ impl BlockBuf {
|
||||
|
||||
ret = Some(match ret.take() {
|
||||
Some(curr) => {
|
||||
curr.concat(&segment)
|
||||
curr.concat(segment)
|
||||
}
|
||||
None => segment,
|
||||
});
|
||||
|
||||
@@ -92,8 +92,14 @@ impl Bytes {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn concat(&self, other: &Bytes) -> Bytes {
|
||||
Rope::concat(self.clone(), other.clone())
|
||||
/// Concatenate two `Bytes` together
|
||||
pub fn concat(self, other: Bytes) -> Bytes {
|
||||
Rope::concat(self, other)
|
||||
}
|
||||
|
||||
/// Divide one `Bytes` into two at an index
|
||||
pub fn split_at(self, mid: usize) -> (Bytes, Bytes) {
|
||||
(self.slice_to(mid), self.slice_from(mid))
|
||||
}
|
||||
|
||||
/// Returns a new ByteStr value containing the byte range between `begin`
|
||||
|
||||
@@ -29,6 +29,7 @@ pub mod buf {
|
||||
pub use imp::buf::slice::SliceBuf;
|
||||
pub use imp::buf::append::AppendBuf;
|
||||
pub use imp::buf::block::{BlockBuf, BlockBufCursor};
|
||||
pub use imp::buf::bound::{BoundBuf};
|
||||
pub use imp::buf::ring::RingBuf;
|
||||
pub use imp::buf::take::Take;
|
||||
pub use imp::bytes::BytesBuf;
|
||||
|
||||
+5
-5
@@ -57,7 +57,7 @@ pub fn test_rope_concat_two_byte_str() {
|
||||
let left = Bytes::from(TEST_BYTES_1);
|
||||
let right = Bytes::from(TEST_BYTES_2);
|
||||
|
||||
let both = left.concat(&right);
|
||||
let both = left.concat(right);
|
||||
|
||||
assert_eq!(both.len(), TEST_BYTES_1.len() + TEST_BYTES_2.len());
|
||||
|
||||
@@ -71,13 +71,13 @@ pub fn test_rope_concat_two_byte_str() {
|
||||
#[test]
|
||||
pub fn test_rope_equality() {
|
||||
let a = Bytes::from(&b"Mary had a little lamb, its fleece was white as snow; "[..])
|
||||
.concat(&Bytes::from(&b"And everywhere that Mary went, the lamb was sure to go."[..]));
|
||||
.concat(Bytes::from(&b"And everywhere that Mary went, the lamb was sure to go."[..]));
|
||||
|
||||
let b = Bytes::from(&b"Mary had a little lamb, "[..])
|
||||
.concat(&Bytes::from(&b"its fleece was white as snow; "[..]))
|
||||
.concat(Bytes::from(&b"its fleece was white as snow; "[..]))
|
||||
.concat(
|
||||
&Bytes::from(&b"And everywhere that Mary went, "[..])
|
||||
.concat(&Bytes::from(&b"the lamb was sure to go."[..])));
|
||||
Bytes::from(&b"And everywhere that Mary went, "[..])
|
||||
.concat(Bytes::from(&b"the lamb was sure to go."[..])));
|
||||
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user