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
+28
View File
@@ -720,3 +720,31 @@ impl<T: AsRef<[u8]>> Buf for io::Cursor<T> {
self.set_position(pos as u64);
}
}
impl Buf for Option<[u8; 1]> {
fn remaining(&self) -> usize {
if self.is_some() {
1
} else {
0
}
}
fn bytes(&self) -> &[u8] {
self.as_ref().map(AsRef::as_ref)
.unwrap_or(Default::default())
}
fn advance(&mut self, cnt: usize) {
if cnt == 0 {
return;
}
if self.is_none() {
panic!("overflow");
} else {
assert_eq!(1, cnt);
*self = None;
}
}
}