Remove buf::Source in favor of buf::IntoBuf

The `Source` trait was essentially covering the same case as `IntoBuf`,
so remove it.

While technically a breaking change, this should not have any impact due
to:

1) There are no reverse dependencies that currently depend on `bytes`
2) Source was not supposed to be implemented externally
3) IntoBuf provides the same implementations as `Source`

Given these points, the change should be safe to apply.
This commit is contained in:
Carl Lerche
2017-03-07 11:30:08 -08:00
parent d70f575afd
commit 06b94c55b0
6 changed files with 123 additions and 154 deletions
+24 -8
View File
@@ -79,6 +79,14 @@ impl IntoBuf for Vec<u8> {
}
}
impl<'a> IntoBuf for &'a Vec<u8> {
type Buf = io::Cursor<&'a [u8]>;
fn into_buf(self) -> Self::Buf {
io::Cursor::new(&self[..])
}
}
// Kind of annoying... but this impl is required to allow passing `&'static
// [u8]` where for<'a> &'a T: IntoBuf is required.
impl<'a> IntoBuf for &'a &'static [u8] {
@@ -97,14 +105,6 @@ impl<'a> IntoBuf for &'a &'static str {
}
}
impl<'a> IntoBuf for &'a Vec<u8> {
type Buf = io::Cursor<&'a [u8]>;
fn into_buf(self) -> Self::Buf {
io::Cursor::new(&self[..])
}
}
impl IntoBuf for String {
type Buf = io::Cursor<Vec<u8>>;
@@ -120,3 +120,19 @@ impl<'a> IntoBuf for &'a String {
self.as_bytes().into_buf()
}
}
impl IntoBuf for u8 {
type Buf = Option<[u8; 1]>;
fn into_buf(self) -> Self::Buf {
Some([self])
}
}
impl IntoBuf for i8 {
type Buf = Option<[u8; 1]>;
fn into_buf(self) -> Self::Buf {
Some([self as u8; 1])
}
}