Lines Matching refs:bytes

3 use bytes::{Buf, BufMut, Bytes, BytesMut};
181 let mut bytes = BytesMut::with_capacity(1024); in split_off_uninitialized() localVariable
182 let other = bytes.split_off(128); in split_off_uninitialized()
184 assert_eq!(bytes.len(), 0); in split_off_uninitialized()
185 assert_eq!(bytes.capacity(), 128); in split_off_uninitialized()
197 let mut bytes = Bytes::from(&s[..]); in split_off_to_loop() localVariable
198 let off = bytes.split_off(i); in split_off_to_loop()
199 assert_eq!(i, bytes.len()); in split_off_to_loop()
201 sum.extend(bytes.iter()); in split_off_to_loop()
206 let mut bytes = BytesMut::from(&s[..]); in split_off_to_loop() localVariable
207 let off = bytes.split_off(i); in split_off_to_loop()
208 assert_eq!(i, bytes.len()); in split_off_to_loop()
210 sum.extend(&bytes); in split_off_to_loop()
215 let mut bytes = Bytes::from(&s[..]); in split_off_to_loop() localVariable
216 let off = bytes.split_to(i); in split_off_to_loop()
220 sum.extend(bytes.iter()); in split_off_to_loop()
224 let mut bytes = BytesMut::from(&s[..]); in split_off_to_loop() localVariable
225 let off = bytes.split_to(i); in split_off_to_loop()
229 sum.extend(&bytes); in split_off_to_loop()
286 let mut bytes = BytesMut::with_capacity(1024); in split_to_uninitialized() localVariable
287 let _other = bytes.split_to(128); in split_to_uninitialized()
293 let mut bytes = BytesMut::with_capacity(100); in split_off_to_at_gt_len() localVariable
294 bytes.put_slice(&[10, 20, 30, 40]); in split_off_to_at_gt_len()
295 bytes.freeze() in split_off_to_at_gt_len()
412 let mut bytes = BytesMut::from(&b"hello world"[..]); in fns_defined_for_bytes_mut() localVariable
414 bytes.as_ptr(); in fns_defined_for_bytes_mut()
415 bytes.as_mut_ptr(); in fns_defined_for_bytes_mut()
418 let v: Vec<u8> = bytes.as_ref().iter().cloned().collect(); in fns_defined_for_bytes_mut()
419 assert_eq!(&v[..], bytes); in fns_defined_for_bytes_mut()
425 let mut bytes = BytesMut::from(LONG); in reserve_convert() localVariable
426 bytes.reserve(64); in reserve_convert()
427 assert_eq!(bytes.capacity(), LONG.len() + 64); in reserve_convert()
430 let mut bytes = BytesMut::from(LONG); in reserve_convert() localVariable
431 let a = bytes.split_to(30); in reserve_convert()
433 bytes.reserve(128); in reserve_convert()
434 assert!(bytes.capacity() >= bytes.len() + 128); in reserve_convert()
441 let mut bytes = BytesMut::with_capacity(64); in reserve_growth() localVariable
442 bytes.put("hello world".as_bytes()); in reserve_growth()
443 let _ = bytes.split(); in reserve_growth()
445 bytes.reserve(65); in reserve_growth()
446 assert_eq!(bytes.capacity(), 128); in reserve_growth()
451 let mut bytes = BytesMut::with_capacity(1024); in reserve_allocates_at_least_original_capacity() localVariable
454 bytes.put_u8(i as u8); in reserve_allocates_at_least_original_capacity()
457 let _other = bytes.split(); in reserve_allocates_at_least_original_capacity()
459 bytes.reserve(16); in reserve_allocates_at_least_original_capacity()
460 assert_eq!(bytes.capacity(), 1024); in reserve_allocates_at_least_original_capacity()
468 let mut bytes = BytesMut::with_capacity(SIZE); in reserve_max_original_capacity_value() localVariable
471 bytes.put_u8(0u8); in reserve_max_original_capacity_value()
474 let _other = bytes.split(); in reserve_max_original_capacity_value()
476 bytes.reserve(16); in reserve_max_original_capacity_value()
477 assert_eq!(bytes.capacity(), 64 * 1024); in reserve_max_original_capacity_value()
482 let mut bytes = BytesMut::with_capacity(16); in reserve_vec_recycling() localVariable
483 assert_eq!(bytes.capacity(), 16); in reserve_vec_recycling()
484 let addr = bytes.as_ptr() as usize; in reserve_vec_recycling()
485 bytes.put("0123456789012345".as_bytes()); in reserve_vec_recycling()
486 assert_eq!(bytes.as_ptr() as usize, addr); in reserve_vec_recycling()
487 bytes.advance(10); in reserve_vec_recycling()
488 assert_eq!(bytes.capacity(), 6); in reserve_vec_recycling()
489 bytes.reserve(8); in reserve_vec_recycling()
490 assert_eq!(bytes.capacity(), 16); in reserve_vec_recycling()
491 assert_eq!(bytes.as_ptr() as usize, addr); in reserve_vec_recycling()
496 let mut bytes = BytesMut::with_capacity(1000); in reserve_in_arc_unique_does_not_overallocate() localVariable
497 let _ = bytes.split(); in reserve_in_arc_unique_does_not_overallocate()
501 assert_eq!(1000, bytes.capacity()); in reserve_in_arc_unique_does_not_overallocate()
502 bytes.reserve(2001); in reserve_in_arc_unique_does_not_overallocate()
503 assert_eq!(2001, bytes.capacity()); in reserve_in_arc_unique_does_not_overallocate()
508 let mut bytes = BytesMut::with_capacity(1000); in reserve_in_arc_unique_doubles() localVariable
509 let _ = bytes.split(); in reserve_in_arc_unique_doubles()
513 assert_eq!(1000, bytes.capacity()); in reserve_in_arc_unique_doubles()
514 bytes.reserve(1001); in reserve_in_arc_unique_doubles()
515 assert_eq!(2000, bytes.capacity()); in reserve_in_arc_unique_doubles()
520 let mut bytes = BytesMut::with_capacity(1000); in reserve_in_arc_nonunique_does_not_overallocate() localVariable
521 let _copy = bytes.split(); in reserve_in_arc_nonunique_does_not_overallocate()
525 assert_eq!(1000, bytes.capacity()); in reserve_in_arc_nonunique_does_not_overallocate()
526 bytes.reserve(2001); in reserve_in_arc_nonunique_does_not_overallocate()
527 assert_eq!(2001, bytes.capacity()); in reserve_in_arc_nonunique_does_not_overallocate()
532 let mut bytes = BytesMut::with_capacity(0); in extend_mut() localVariable
533 bytes.extend(LONG); in extend_mut()
534 assert_eq!(*bytes, LONG[..]); in extend_mut()
540 let mut bytes = BytesMut::new(); in extend_from_slice_mut() localVariable
541 bytes.extend_from_slice(&LONG[..i]); in extend_from_slice_mut()
542 bytes.extend_from_slice(&LONG[i..]); in extend_from_slice_mut()
543 assert_eq!(LONG[..], *bytes); in extend_from_slice_mut()
549 let mut bytes = BytesMut::with_capacity(0); in extend_mut_without_size_hint() localVariable
553 bytes.extend(std::iter::from_fn(|| long_iter.next())); in extend_mut_without_size_hint()
554 assert_eq!(*bytes, LONG[..]); in extend_mut_without_size_hint()
650 let bytes = Bytes::from(&b"The quick red fox"[..]); in partial_eq_bytesmut() localVariable
652 assert!(bytes == bytesmut); in partial_eq_bytesmut()
653 assert!(bytesmut == bytes); in partial_eq_bytesmut()
850 fn test_slice_ref(bytes: &Bytes, start: usize, end: usize, expected: &[u8]) { in test_slice_ref()
851 let slice = &(bytes.as_ref()[start..end]); in test_slice_ref()
852 let sub = bytes.slice_ref(&slice); in test_slice_ref()
858 let bytes = Bytes::from(&b"012345678"[..]); in slice_ref_works() localVariable
860 test_slice_ref(&bytes, 0, 0, b""); in slice_ref_works()
861 test_slice_ref(&bytes, 0, 3, b"012"); in slice_ref_works()
862 test_slice_ref(&bytes, 2, 6, b"2345"); in slice_ref_works()
863 test_slice_ref(&bytes, 7, 9, b"78"); in slice_ref_works()
864 test_slice_ref(&bytes, 9, 9, b""); in slice_ref_works()
869 let bytes = Bytes::from(&b""[..]); in slice_ref_empty() localVariable
870 let slice = &(bytes.as_ref()[0..0]); in slice_ref_empty()
872 let sub = bytes.slice_ref(&slice); in slice_ref_empty()
878 let bytes = Bytes::from(&b"abcde"[..]); in slice_ref_empty_subslice() localVariable
879 let subbytes = bytes.slice(0..0); in slice_ref_empty_subslice()
883 assert_eq!(Bytes::new(), bytes.slice_ref(slice)); in slice_ref_empty_subslice()
889 let bytes = Bytes::from(&b"012345678"[..]); in slice_ref_catches_not_a_subset() localVariable
892 bytes.slice_ref(slice); in slice_ref_catches_not_a_subset()
897 let bytes = Bytes::from(&b"012345678"[..]); in slice_ref_not_an_empty_subset() localVariable
900 assert_eq!(Bytes::new(), bytes.slice_ref(slice)); in slice_ref_not_an_empty_subset()
905 let bytes = Bytes::new(); in empty_slice_ref_not_an_empty_subset() localVariable
908 assert_eq!(Bytes::new(), bytes.slice_ref(slice)); in empty_slice_ref_not_an_empty_subset()
913 let mut bytes = BytesMut::with_capacity(1024); in bytes_buf_mut_advance() localVariable
916 let ptr = bytes.chunk_mut().as_mut_ptr(); in bytes_buf_mut_advance()
917 assert_eq!(1024, bytes.chunk_mut().len()); in bytes_buf_mut_advance()
919 bytes.advance_mut(10); in bytes_buf_mut_advance()
921 let next = bytes.chunk_mut().as_mut_ptr(); in bytes_buf_mut_advance()
922 assert_eq!(1024 - 10, bytes.chunk_mut().len()); in bytes_buf_mut_advance()
926 bytes.advance_mut(1024 - 10); in bytes_buf_mut_advance()
929 assert_eq!(1024, bytes.chunk_mut().len()); in bytes_buf_mut_advance()
935 use bytes::{Buf, BytesMut}; in bytes_buf_mut_reuse_when_fully_consumed()
952 let mut bytes = BytesMut::with_capacity(1024); in bytes_reserve_overflow() localVariable
953 bytes.put_slice(b"hello world"); in bytes_reserve_overflow()
955 bytes.reserve(usize::MAX); in bytes_reserve_overflow()