We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e3ef866 commit 44f2bc6Copy full SHA for 44f2bc6
src/http/buf.rs
@@ -176,6 +176,18 @@ impl fmt::Debug for MemBuf {
176
}
177
178
179
+impl From<Vec<u8>> for MemBuf {
180
+ fn from(mut vec: Vec<u8>) -> MemBuf {
181
+ let end = vec.iter().find(|&&x| x == 0).map(|&x| x as usize).unwrap_or(vec.len());
182
+ vec.shrink_to_fit();
183
+ MemBuf {
184
+ buf: Arc::new(UnsafeCell::new(vec)),
185
+ start: 0,
186
+ end: end,
187
+ }
188
189
+}
190
+
191
pub struct MemSlice {
192
buf: Arc<UnsafeCell<Vec<u8>>>,
193
start: usize,
@@ -284,8 +296,7 @@ mod tests {
284
296
285
297
#[test]
286
298
fn test_mem_slice_slice() {
287
- let mut buf = MemBuf::with_capacity(32);
288
- buf.read_from(&mut &b"Hello World"[..]).unwrap();
299
+ let mut buf = MemBuf::from(b"Hello World".to_vec());
289
300
290
301
let len = buf.len();
291
302
let full = buf.slice(len);
0 commit comments