• Home
  • Raw
  • Download

Lines Matching full:bytes

3 use bytes::{Buf, BufMut, Bytes, BytesMut};
15 is_sync::<Bytes>(); in test_bounds()
17 is_send::<Bytes>(); in test_bounds()
26 mem::size_of::<Bytes>(), in test_layout()
28 "Bytes size should be 4 words", in test_layout()
37 mem::size_of::<Bytes>(), in test_layout()
38 mem::size_of::<Option<Bytes>>(), in test_layout()
39 "Bytes should be same size as Option<Bytes>", in test_layout()
51 let a = Bytes::from(&b"abcdefgh"[..]); in from_slice()
70 let a = format!("{:?}", Bytes::from(&b"abcdefg"[..])); in fmt()
101 let a = Bytes::from(&b"abcdefg"[..]); in len()
107 let a = Bytes::from(&b""[..]); in len()
116 let a = Bytes::from(&b"hello world"[..]); in index()
122 let a = Bytes::from(&b"hello world"[..]); in slice()
146 let a = Bytes::from(&b"hello world"[..]); in slice_oob_1()
153 let a = Bytes::from(&b"hello world"[..]); in slice_oob_2()
159 let mut hello = Bytes::from(&b"helloworld"[..]); in split_off()
175 let mut hello = Bytes::from(&b"helloworld"[..]); in split_off_oob()
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()
238 let mut a = Bytes::from_static(SHORT); in split_to_1()
245 let mut a = Bytes::copy_from_slice(LONG); in split_to_1()
251 let mut a = Bytes::copy_from_slice(LONG); in split_to_1()
260 let mut a = Bytes::from(LONG); in split_to_2()
272 let mut hello = Bytes::from(&b"helloworld"[..]); in split_to_oob()
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 fn make_bytes() -> Bytes { in split_off_to_at_gt_len()
294 let mut bytes = BytesMut::with_capacity(100); in split_off_to_at_gt_len() localVariable
295 bytes.put_slice(&[10, 20, 30, 40]); in split_off_to_at_gt_len()
296 bytes.freeze() in split_off_to_at_gt_len()
318 let mut hello = Bytes::from(s); in truncate()
413 let mut bytes = BytesMut::from(&b"hello world"[..]); in fns_defined_for_bytes_mut() localVariable
415 let _ = bytes.as_ptr(); in fns_defined_for_bytes_mut()
416 let _ = bytes.as_mut_ptr(); in fns_defined_for_bytes_mut()
419 let v: Vec<u8> = bytes.as_ref().iter().cloned().collect(); in fns_defined_for_bytes_mut()
420 assert_eq!(&v[..], bytes); in fns_defined_for_bytes_mut()
426 let mut bytes = BytesMut::from(LONG); in reserve_convert() localVariable
427 bytes.reserve(64); in reserve_convert()
428 assert_eq!(bytes.capacity(), LONG.len() + 64); in reserve_convert()
431 let mut bytes = BytesMut::from(LONG); in reserve_convert() localVariable
432 let a = bytes.split_to(30); in reserve_convert()
434 bytes.reserve(128); in reserve_convert()
435 assert!(bytes.capacity() >= bytes.len() + 128); in reserve_convert()
442 let mut bytes = BytesMut::with_capacity(64); in reserve_growth() localVariable
443 bytes.put("hello world".as_bytes()); in reserve_growth()
444 let _ = bytes.split(); in reserve_growth()
446 bytes.reserve(65); in reserve_growth()
447 assert_eq!(bytes.capacity(), 117); in reserve_growth()
452 let mut bytes = BytesMut::with_capacity(1024); in reserve_allocates_at_least_original_capacity() localVariable
455 bytes.put_u8(i as u8); in reserve_allocates_at_least_original_capacity()
458 let _other = bytes.split(); in reserve_allocates_at_least_original_capacity()
460 bytes.reserve(16); in reserve_allocates_at_least_original_capacity()
461 assert_eq!(bytes.capacity(), 1024); in reserve_allocates_at_least_original_capacity()
469 let mut bytes = BytesMut::with_capacity(SIZE); in reserve_max_original_capacity_value() localVariable
472 bytes.put_u8(0u8); in reserve_max_original_capacity_value()
475 let _other = bytes.split(); in reserve_max_original_capacity_value()
477 bytes.reserve(16); in reserve_max_original_capacity_value()
478 assert_eq!(bytes.capacity(), 64 * 1024); in reserve_max_original_capacity_value()
483 let mut bytes = BytesMut::with_capacity(16); in reserve_vec_recycling() localVariable
484 assert_eq!(bytes.capacity(), 16); in reserve_vec_recycling()
485 let addr = bytes.as_ptr() as usize; in reserve_vec_recycling()
486 bytes.put("0123456789012345".as_bytes()); in reserve_vec_recycling()
487 assert_eq!(bytes.as_ptr() as usize, addr); in reserve_vec_recycling()
488 bytes.advance(10); in reserve_vec_recycling()
489 assert_eq!(bytes.capacity(), 6); in reserve_vec_recycling()
490 bytes.reserve(8); in reserve_vec_recycling()
491 assert_eq!(bytes.capacity(), 16); in reserve_vec_recycling()
492 assert_eq!(bytes.as_ptr() as usize, addr); in reserve_vec_recycling()
497 let mut bytes = BytesMut::with_capacity(1000); in reserve_in_arc_unique_does_not_overallocate() localVariable
498 let _ = bytes.split(); in reserve_in_arc_unique_does_not_overallocate()
500 // now bytes is Arc and refcount == 1 in reserve_in_arc_unique_does_not_overallocate()
502 assert_eq!(1000, bytes.capacity()); in reserve_in_arc_unique_does_not_overallocate()
503 bytes.reserve(2001); in reserve_in_arc_unique_does_not_overallocate()
504 assert_eq!(2001, bytes.capacity()); in reserve_in_arc_unique_does_not_overallocate()
509 let mut bytes = BytesMut::with_capacity(1000); in reserve_in_arc_unique_doubles() localVariable
510 let _ = bytes.split(); in reserve_in_arc_unique_doubles()
512 // now bytes is Arc and refcount == 1 in reserve_in_arc_unique_doubles()
514 assert_eq!(1000, bytes.capacity()); in reserve_in_arc_unique_doubles()
515 bytes.reserve(1001); in reserve_in_arc_unique_doubles()
516 assert_eq!(2000, bytes.capacity()); in reserve_in_arc_unique_doubles()
521 let mut bytes = BytesMut::from(LONG); in reserve_in_arc_unique_does_not_overallocate_after_split() localVariable
522 let orig_capacity = bytes.capacity(); in reserve_in_arc_unique_does_not_overallocate_after_split()
523 drop(bytes.split_off(LONG.len() / 2)); in reserve_in_arc_unique_does_not_overallocate_after_split()
525 // now bytes is Arc and refcount == 1 in reserve_in_arc_unique_does_not_overallocate_after_split()
527 let new_capacity = bytes.capacity(); in reserve_in_arc_unique_does_not_overallocate_after_split()
528 bytes.reserve(orig_capacity - new_capacity); in reserve_in_arc_unique_does_not_overallocate_after_split()
529 assert_eq!(bytes.capacity(), orig_capacity); in reserve_in_arc_unique_does_not_overallocate_after_split()
534 let mut bytes = BytesMut::from(LONG); in reserve_in_arc_unique_does_not_overallocate_after_multiple_splits() localVariable
535 let orig_capacity = bytes.capacity(); in reserve_in_arc_unique_does_not_overallocate_after_multiple_splits()
537 drop(bytes.split_off(LONG.len() / 2)); in reserve_in_arc_unique_does_not_overallocate_after_multiple_splits()
539 // now bytes is Arc and refcount == 1 in reserve_in_arc_unique_does_not_overallocate_after_multiple_splits()
541 let new_capacity = bytes.capacity(); in reserve_in_arc_unique_does_not_overallocate_after_multiple_splits()
542 bytes.reserve(orig_capacity - new_capacity); in reserve_in_arc_unique_does_not_overallocate_after_multiple_splits()
544 assert_eq!(bytes.capacity(), orig_capacity); in reserve_in_arc_unique_does_not_overallocate_after_multiple_splits()
549 let mut bytes = BytesMut::with_capacity(1000); in reserve_in_arc_nonunique_does_not_overallocate() localVariable
550 let _copy = bytes.split(); in reserve_in_arc_nonunique_does_not_overallocate()
552 // now bytes is Arc and refcount == 2 in reserve_in_arc_nonunique_does_not_overallocate()
554 assert_eq!(1000, bytes.capacity()); in reserve_in_arc_nonunique_does_not_overallocate()
555 bytes.reserve(2001); in reserve_in_arc_nonunique_does_not_overallocate()
556 assert_eq!(2001, bytes.capacity()); in reserve_in_arc_nonunique_does_not_overallocate()
564 let mut bytes = BytesMut::with_capacity(1000); in reserve_shared_reuse() localVariable
565 bytes.put_slice(b"Hello, World!"); in reserve_shared_reuse()
566 drop(bytes.split()); in reserve_shared_reuse()
568 bytes.put_slice(b"!123ex123,sadchELLO,_wORLD!"); in reserve_shared_reuse()
570 drop(bytes.split_off(9)); in reserve_shared_reuse()
571 assert_eq!(&*bytes, b"!123ex123"); in reserve_shared_reuse()
573 bytes.reserve(2000); in reserve_shared_reuse()
574 assert_eq!(&*bytes, b"!123ex123"); in reserve_shared_reuse()
575 assert_eq!(bytes.capacity(), 2009); in reserve_shared_reuse()
580 let mut bytes = BytesMut::with_capacity(0); in extend_mut() localVariable
581 bytes.extend(LONG); in extend_mut()
582 assert_eq!(*bytes, LONG[..]); in extend_mut()
588 let mut bytes = BytesMut::new(); in extend_from_slice_mut() localVariable
589 bytes.extend_from_slice(&LONG[..i]); in extend_from_slice_mut()
590 bytes.extend_from_slice(&LONG[i..]); in extend_from_slice_mut()
591 assert_eq!(LONG[..], *bytes); in extend_from_slice_mut()
597 let mut bytes = BytesMut::with_capacity(0); in extend_mut_from_bytes() localVariable
598 bytes.extend([Bytes::from(LONG)]); in extend_mut_from_bytes()
599 assert_eq!(*bytes, LONG[..]); in extend_mut_from_bytes()
604 let mut bytes = BytesMut::with_capacity(0); in extend_mut_without_size_hint() localVariable
608 bytes.extend(std::iter::from_fn(|| long_iter.next())); in extend_mut_without_size_hint()
609 assert_eq!(*bytes, LONG[..]); in extend_mut_without_size_hint()
614 let mut a = Bytes::from_static(b"ab"); in from_static()
623 let mut a = Bytes::from_static(b"hello world"); in advance_static()
630 let mut a = Bytes::from(b"hello world boooo yah world zomg wat wat".to_vec()); in advance_vec()
679 let buf = Arc::new(Bytes::copy_from_slice(&data[..])); in stress()
690 let buf: Bytes = (*buf).clone(); in stress()
705 let bytes = Bytes::from(&b"The quick red fox"[..]); in partial_eq_bytesmut() localVariable
707 assert!(bytes == bytesmut); in partial_eq_bytesmut()
708 assert!(bytesmut == bytes); in partial_eq_bytesmut()
709 let bytes2 = Bytes::from(&b"Jumped over the lazy brown dog"[..]); in partial_eq_bytesmut()
717 let buf = Bytes::from(&b"aaabbbcccddd"[..]);
729 let buf = Bytes::from(&b"aaabbbcccddd"[..]);
732 let other = Bytes::new();
741 let mut buf = Bytes::new();
743 let mut other = Bytes::with_capacity(64);
752 let mut buf = Bytes::with_capacity(64);
757 let mut buf2 = Bytes::with_capacity(64);
768 let mut buf = Bytes::with_capacity(64);
781 let mut buf = Bytes::with_capacity(64);
794 let mut buf = Bytes::with_capacity(64);
915 let actual: Bytes = iter::repeat(b'x') in from_iter_no_size_hint()
930 fn test_slice_ref(bytes: &Bytes, start: usize, end: usize, expected: &[u8]) { in test_slice_ref() argument
931 let slice = &(bytes.as_ref()[start..end]); in test_slice_ref()
932 let sub = bytes.slice_ref(slice); in test_slice_ref()
938 let bytes = Bytes::from(&b"012345678"[..]); in slice_ref_works() localVariable
940 test_slice_ref(&bytes, 0, 0, b""); in slice_ref_works()
941 test_slice_ref(&bytes, 0, 3, b"012"); in slice_ref_works()
942 test_slice_ref(&bytes, 2, 6, b"2345"); in slice_ref_works()
943 test_slice_ref(&bytes, 7, 9, b"78"); in slice_ref_works()
944 test_slice_ref(&bytes, 9, 9, b""); in slice_ref_works()
949 let bytes = Bytes::from(&b""[..]); in slice_ref_empty() localVariable
950 let slice = &(bytes.as_ref()[0..0]); in slice_ref_empty()
952 let sub = bytes.slice_ref(slice); in slice_ref_empty()
958 let bytes = Bytes::from(&b"abcde"[..]); in slice_ref_empty_subslice() localVariable
959 let subbytes = bytes.slice(0..0); in slice_ref_empty_subslice()
961 // The `slice` object is derived from the original `bytes` object in slice_ref_empty_subslice()
963 assert_eq!(Bytes::new(), bytes.slice_ref(slice)); in slice_ref_empty_subslice()
969 let bytes = Bytes::from(&b"012345678"[..]); in slice_ref_catches_not_a_subset() localVariable
972 bytes.slice_ref(slice); in slice_ref_catches_not_a_subset()
977 let bytes = Bytes::from(&b"012345678"[..]); in slice_ref_not_an_empty_subset() localVariable
980 assert_eq!(Bytes::new(), bytes.slice_ref(slice)); in slice_ref_not_an_empty_subset()
985 let bytes = Bytes::new(); in empty_slice_ref_not_an_empty_subset() localVariable
988 assert_eq!(Bytes::new(), bytes.slice_ref(slice)); in empty_slice_ref_not_an_empty_subset()
993 let mut bytes = BytesMut::with_capacity(1024); in bytes_buf_mut_advance() localVariable
996 let ptr = bytes.chunk_mut().as_mut_ptr(); in bytes_buf_mut_advance()
997 assert_eq!(1024, bytes.chunk_mut().len()); in bytes_buf_mut_advance()
999 bytes.advance_mut(10); in bytes_buf_mut_advance()
1001 let next = bytes.chunk_mut().as_mut_ptr(); in bytes_buf_mut_advance()
1002 assert_eq!(1024 - 10, bytes.chunk_mut().len()); in bytes_buf_mut_advance()
1006 bytes.advance_mut(1024 - 10); in bytes_buf_mut_advance()
1009 assert_eq!(1024, bytes.chunk_mut().len()); in bytes_buf_mut_advance()
1015 use bytes::{Buf, BytesMut}; in bytes_buf_mut_reuse_when_fully_consumed()
1032 let mut bytes = BytesMut::with_capacity(1024); in bytes_reserve_overflow() localVariable
1033 bytes.put_slice(b"hello world"); in bytes_reserve_overflow()
1035 bytes.reserve(usize::MAX); in bytes_reserve_overflow()
1040 // See https://github.com/tokio-rs/bytes/issues/340 in bytes_with_capacity_but_empty()
1042 let _ = Bytes::from(vec); in bytes_with_capacity_but_empty()
1047 let mut bytes = BytesMut::new(); in bytes_put_bytes() localVariable
1048 bytes.put_u8(17); in bytes_put_bytes()
1049 bytes.put_bytes(19, 2); in bytes_put_bytes()
1050 assert_eq!([17, 19, 19], bytes.as_ref()); in bytes_put_bytes()
1055 // See https://github.com/tokio-rs/bytes/issues/340 in box_slice_empty()
1057 let b = Bytes::from(empty); in box_slice_empty()
1066 let mut bytes = BytesMut::new(); in bytes_into_vec() localVariable
1067 bytes.put_slice(content); in bytes_into_vec()
1069 let vec: Vec<u8> = bytes.into(); in bytes_into_vec()
1073 let mut bytes = BytesMut::new(); in bytes_into_vec() localVariable
1074 bytes.put_slice(b"abcdewe23"); in bytes_into_vec()
1075 bytes.put_slice(content); in bytes_into_vec()
1077 // Overwrite the bytes to make sure only one reference to the underlying in bytes_into_vec()
1079 bytes = bytes.split_off(9); in bytes_into_vec()
1081 let vec: Vec<u8> = bytes.into(); in bytes_into_vec()
1087 let mut bytes = BytesMut::new(); in bytes_into_vec() localVariable
1088 bytes.put_slice(prefix); in bytes_into_vec()
1089 bytes.put_slice(content); in bytes_into_vec()
1091 let vec: Vec<u8> = bytes.split_off(prefix.len()).into(); in bytes_into_vec()
1094 let vec: Vec<u8> = bytes.into(); in bytes_into_vec()
1102 let vec: Vec<u8> = Bytes::from_static(bs).into(); in test_bytes_into_vec()
1109 // Set kind to KIND_ARC so that after freeze, Bytes will use bytes_mut.SHARED_VTABLE in test_bytes_into_vec()
1144 let b1 = Bytes::from(vec.clone()); in test_bytes_into_vec_promotable_even()
1148 let b1 = Bytes::from(vec.clone()); in test_bytes_into_vec_promotable_even()
1153 let b1 = Bytes::from(vec.clone()); in test_bytes_into_vec_promotable_even()
1161 let mut b1 = Bytes::from(vec.clone()); in test_bytes_into_vec_promotable_even()
1172 let b = Bytes::from(vec); in test_bytes_vec_conversion()
1177 let mut b = Bytes::from(v); in test_bytes_vec_conversion()
1189 let b2 = Bytes::from(b1); in test_bytes_mut_conversion()
1194 let mut b = Bytes::from(v); in test_bytes_mut_conversion()
1208 let _ = Bytes::from(v); in test_bytes_capacity_len()