|
10 | 10 | //! |
11 | 11 | //! | Feature | Implementations | |
12 | 12 | //! | ------------ | ---------------------------------------------------------------- | |
13 | | -//! | `zerocopy` | `&'static [T]`, `Box<T>` and `Vec<T>` for `T: IntoBytes + Immutable` | |
14 | | -//! | *(none)* | `&'static [u8]`, `Box<[u8]>`, `Vec<u8>`, `String`, `&'static str` | |
| 13 | +//! | `zerocopy` | `&'static [T]`, `Box<T>`, `Vec<T>` for `T: IntoBytes + Immutable` | |
| 14 | +//! | *(none)* | `&'static [u8]`, `Box<[u8]>`, `Vec<u8>`, `String`, `&'static str`, `Cow<'static, T>` for `T: AsRef<[u8]>` | |
15 | 15 | //! | `bytes` | `bytes::Bytes` | |
16 | 16 | //! | `ownedbytes` | `ownedbytes::OwnedBytes` | |
17 | 17 | //! | `mmap` | `memmap2::Mmap` and `ByteOwner` for `memmap2::MmapRaw` | |
@@ -145,41 +145,27 @@ unsafe impl ByteSource for String { |
145 | 145 | } |
146 | 146 | } |
147 | 147 |
|
148 | | -#[cfg(feature = "zerocopy")] |
149 | | -unsafe impl<T> ByteSource for Cow<'static, [T]> |
150 | | -where |
151 | | - T: IntoBytes + Immutable + Sync + Send + Clone + 'static, |
152 | | -{ |
153 | | - type Owner = Self; |
154 | | - |
155 | | - fn as_bytes(&self) -> &[u8] { |
156 | | - let slice: &[T] = self.as_ref(); |
157 | | - IntoBytes::as_bytes(slice) |
158 | | - } |
159 | | - |
160 | | - fn get_owner(self) -> Self::Owner { |
161 | | - self |
162 | | - } |
163 | | -} |
164 | | - |
165 | | -#[cfg(not(feature = "zerocopy"))] |
166 | | -unsafe impl ByteSource for Cow<'static, [u8]> { |
| 148 | +unsafe impl ByteSource for &'static str { |
167 | 149 | type Owner = Self; |
168 | 150 |
|
169 | 151 | fn as_bytes(&self) -> &[u8] { |
170 | | - self.as_ref() |
| 152 | + (*self).as_bytes() |
171 | 153 | } |
172 | 154 |
|
173 | 155 | fn get_owner(self) -> Self::Owner { |
174 | 156 | self |
175 | 157 | } |
176 | 158 | } |
177 | 159 |
|
178 | | -unsafe impl ByteSource for &'static str { |
| 160 | +unsafe impl<T> ByteSource for Cow<'static, T> |
| 161 | +where |
| 162 | + T: ?Sized + ToOwned + AsRef<[u8]> + Sync + Send + 'static, |
| 163 | + T::Owned: Sync + Send + 'static, |
| 164 | +{ |
179 | 165 | type Owner = Self; |
180 | 166 |
|
181 | 167 | fn as_bytes(&self) -> &[u8] { |
182 | | - (*self).as_bytes() |
| 168 | + self.as_ref().as_ref() |
183 | 169 | } |
184 | 170 |
|
185 | 171 | fn get_owner(self) -> Self::Owner { |
|
0 commit comments