mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-22 00:00:15 +02:00
Add FromIterator impl (#148)
This commit is contained in:
@@ -7,6 +7,7 @@ use std::borrow::Borrow;
|
|||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::sync::atomic::{self, AtomicUsize, AtomicPtr};
|
use std::sync::atomic::{self, AtomicUsize, AtomicPtr};
|
||||||
use std::sync::atomic::Ordering::{Relaxed, Acquire, Release, AcqRel};
|
use std::sync::atomic::Ordering::{Relaxed, Acquire, Release, AcqRel};
|
||||||
|
use std::iter::{FromIterator, Iterator};
|
||||||
|
|
||||||
/// A reference counted contiguous slice of memory.
|
/// A reference counted contiguous slice of memory.
|
||||||
///
|
///
|
||||||
@@ -838,6 +839,27 @@ impl<'a> From<&'a str> for Bytes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FromIterator<u8> for BytesMut {
|
||||||
|
fn from_iter<T: IntoIterator<Item = u8>>(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.put(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromIterator<u8> for Bytes {
|
||||||
|
fn from_iter<T: IntoIterator<Item = u8>>(into_iter: T) -> Self {
|
||||||
|
BytesMut::from_iter(into_iter).freeze()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PartialEq for Bytes {
|
impl PartialEq for Bytes {
|
||||||
fn eq(&self, other: &Bytes) -> bool {
|
fn eq(&self, other: &Bytes) -> bool {
|
||||||
self.inner.as_ref() == other.inner.as_ref()
|
self.inner.as_ref() == other.inner.as_ref()
|
||||||
|
|||||||
Reference in New Issue
Block a user