aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Sean McArthur <sean@seanmonstar.com> 2019-10-16 11:28:50 -0700
committerGravatar Carl Lerche <me@carllerche.com> 2019-10-16 11:28:50 -0700
commit491ebbf79a61f78b699e082d2793e79bb17f3f2e (patch)
treeef82ad3ebfafd5501f37f57081c3425dadc243fb /src
parent43ac8e5494e9404327f971937edb092b8cae6a2b (diff)
downloadbytes-491ebbf79a61f78b699e082d2793e79bb17f3f2e.tar.gz
bytes-491ebbf79a61f78b699e082d2793e79bb17f3f2e.tar.zst
bytes-491ebbf79a61f78b699e082d2793e79bb17f3f2e.zip
Remove Buf impl for &str (#301)
A `&str` cannot arbitrarily advance bytes, since it will panic if advanced to the middle of a Unicode segment.
Diffstat (limited to 'src')
-rw-r--r--src/buf/buf_impl.rs21
-rw-r--r--src/buf/buf_mut.rs8
-rw-r--r--src/bytes_mut.rs4
3 files changed, 8 insertions, 25 deletions
diff --git a/src/buf/buf_impl.rs b/src/buf/buf_impl.rs
index b9e9141..48f8d12 100644
--- a/src/buf/buf_impl.rs
+++ b/src/buf/buf_impl.rs
@@ -903,9 +903,9 @@ pub trait Buf {
/// # Examples
///
/// ```
- /// use bytes::{Buf};
+ /// use bytes::Buf;
///
- /// let bytes = "hello world".to_bytes();
+ /// let bytes = (&b"hello world"[..]).to_bytes();
/// assert_eq!(&bytes[..], &b"hello world"[..]);
/// ```
fn to_bytes(&mut self) -> crate::Bytes {
@@ -971,23 +971,6 @@ impl Buf for &[u8] {
}
}
-impl Buf for &str {
- #[inline]
- fn remaining(&self) -> usize {
- self.len()
- }
-
- #[inline]
- fn bytes(&self) -> &[u8] {
- self.as_bytes()
- }
-
- #[inline]
- fn advance(&mut self, cnt: usize) {
- *self = &self[cnt..];
- }
-}
-
impl Buf for Option<[u8; 1]> {
fn remaining(&self) -> usize {
if self.is_some() {
diff --git a/src/buf/buf_mut.rs b/src/buf/buf_mut.rs
index 1571580..ecf4720 100644
--- a/src/buf/buf_mut.rs
+++ b/src/buf/buf_mut.rs
@@ -24,7 +24,7 @@ use alloc::{vec::Vec, boxed::Box};
///
/// let mut buf = vec![];
///
-/// buf.put("hello world");
+/// buf.put(&b"hello world"[..]);
///
/// assert_eq!(buf, b"hello world");
/// ```
@@ -44,7 +44,7 @@ pub trait BufMut {
/// let mut buf = &mut dst[..];
///
/// let original_remaining = buf.remaining_mut();
- /// buf.put("hello");
+ /// buf.put(&b"hello"[..]);
///
/// assert_eq!(original_remaining - 5, buf.remaining_mut());
/// ```
@@ -114,7 +114,7 @@ pub trait BufMut {
///
/// assert!(buf.has_remaining_mut());
///
- /// buf.put("hello");
+ /// buf.put(&b"hello"[..]);
///
/// assert!(!buf.has_remaining_mut());
/// ```
@@ -217,7 +217,7 @@ pub trait BufMut {
///
/// buf.put_u8(b'h');
/// buf.put(&b"ello"[..]);
- /// buf.put(" world");
+ /// buf.put(&b" world"[..]);
///
/// assert_eq!(buf, b"hello world");
/// ```
diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs
index c5642cf..6777929 100644
--- a/src/bytes_mut.rs
+++ b/src/bytes_mut.rs
@@ -38,7 +38,7 @@ use crate::loom::sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering};
///
/// buf.put_u8(b'h');
/// buf.put_u8(b'e');
-/// buf.put("llo");
+/// buf.put(&b"llo"[..]);
///
/// assert_eq!(&buf[..], b"hello");
///
@@ -219,7 +219,7 @@ impl BytesMut {
/// use std::thread;
///
/// let mut b = BytesMut::with_capacity(64);
- /// b.put("hello world");
+ /// b.put(&b"hello world"[..]);
/// let b1 = b.freeze();
/// let b2 = b1.clone();
///