Implement AsRef for [u8] · rust-lang/rust@da39b9f (original) (raw)

File tree

3 files changed

lines changed

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ macro_rules! specialize_for_lengths {
90 90 $num => {
91 91 for s in iter {
92 92 copy_slice_and_advance!(target, sep_bytes);
93 -let content_bytes = s.borrow().as_ref();
93 +let content_bytes: &[_] = s.borrow().as_ref();
94 94 copy_slice_and_advance!(target, content_bytes);
95 95 }
96 96 },
@@ -99,7 +99,7 @@ macro_rules! specialize_for_lengths {
99 99 // arbitrary non-zero size fallback
100 100 for s in iter {
101 101 copy_slice_and_advance!(target, sep_bytes);
102 -let content_bytes = s.borrow().as_ref();
102 +let content_bytes: &[_] = s.borrow().as_ref();
103 103 copy_slice_and_advance!(target, content_bytes);
104 104 }
105 105 }
Original file line number Diff line number Diff line change
@@ -200,7 +200,13 @@ impl AsRef for ByteStr {
200 200 }
201 201 }
202 202
203 -// `impl AsRef for [u8]` omitted to avoid widespread inference failures
203 +#[unstable(feature = "bstr", issue = "134915")]
204 +impl AsRef<ByteStr> for [u8] {
205 +#[inline]
206 +fn as_ref(&self) -> &ByteStr {
207 +ByteStr::new(self)
208 +}
209 +}
204 210
205 211 #[unstable(feature = "bstr", issue = "134915")]
206 212 impl AsRef<ByteStr> for str {
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ trait Trait {
7 7 fn as_ptr(&self);
8 8 }
9 9
10 -impl<'a> Trait for &'a [u8] {
10 +impl<'a> Trait for &'a [u32] {
11 11 fn as_ptr(&self) {
12 12 self.as_ref().as_ptr();
13 13 }