Debian Codegraph @

tests/tests.rs

raw symbols SCIP
1 // Copyright (c) The buf-list Contributors
2 // SPDX-License-Identifier: Apache-2.0
3
4 use buf_listrust-analyzer cargo buf-list 1.1.2 crate/::BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#;
5 use bytesrust-analyzer cargo bytes 1.3.0 crate/::{Bufrust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#, Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#};
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::IoSlicerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSlice#, opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#};
7
8 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
9 fn test_basicrust-analyzer cargo buf-list 1.1.2 test_basic().() {
10 let mut buf_list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![&b"hello"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().]
11 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
12 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#>();
13 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", buf_list);
14 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 10);
15 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 2);
16
17 let chunk = buf_list.push_chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]push_chunk().(&b"foo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
18 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 13);
19 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 3);
20 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chunk, &b"foo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
21
22 // Try inserting a zero-length chunk. This should not count as a chunk.
23 buf_list.push_chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]push_chunk().(&[] as &[u8]);
24 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 13);
25 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 3);
26
27 {
28 let mut buf_list = buf_list.clonerust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Clone]clone().();
29
30 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]chunk().(), &b"hello"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
31
32 // Advance by 2. This won't consume the first chunk.
33 buf_list.advancerust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]advance().(2);
34 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 11);
35 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 3);
36 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]chunk().(), &b"llo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
37
38 // Advance by 3. This will consume the "hello" chunk exactly.
39 buf_list.advancerust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]advance().(3);
40 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 8);
41 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 2);
42 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]chunk().(), &b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
43
44 // Advance by 6. This will consume the "world" chunk + the first byte of "foo".
45 buf_list.advancerust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]advance().(6);
46 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 2);
47 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 1);
48 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]chunk().(), &b"oo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
49
50 // Advance by 2. This will consume the "foo" chunk exactly.
51 buf_list.advancerust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]advance().(2);
52 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 0);
53 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 0);
54 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]chunk().(), &[] as &[u8]);
55 }
56
57 {
58 // Test chunks_vectored.
59 let mut chunks_vectored = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![IoSlicerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSlice#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`]new().(&[]); 5];
60 let ret = buf_list.chunks_vectoredrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]chunks_vectored().(&mut chunks_vectored);
61 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, 3);
62 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chunks_vectored[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..derefrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`][Deref]deref().(), &b"hello"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
63 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chunks_vectored[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..derefrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`][Deref]deref().(), &b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
64 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chunks_vectored[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..derefrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`][Deref]deref().(), &b"foo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
65 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chunks_vectored[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..derefrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`][Deref]deref().(), &[] as &[u8]);
66
67 // Test chunks_vectored with a smaller buffer.
68 let mut chunks_vectored = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![IoSlicerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSlice#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`]new().(&[]); 2];
69 let ret = buf_list.chunks_vectoredrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]chunks_vectored().(&mut chunks_vectored);
70 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, 2);
71 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chunks_vectored[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..derefrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`][Deref]deref().(), &b"hello"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
72 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chunks_vectored[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..derefrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`][Deref]deref().(), &b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
73
74 // Test with an empty buffer.
75 let mut chunks_vectored = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
76 let ret = buf_list.chunks_vectoredrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]chunks_vectored().(&mut chunks_vectored);
77 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, 0);
78 }
79
80 {
81 // Test copy_to_bytes.
82 let mut buf_list = buf_list.clonerust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Clone]clone().();
83
84 // Copy the first two bytes -- this should just be a refcount.
85 let bytes = buf_list.copy_to_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]copy_to_bytes().(2);
86 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bytes, &b"he"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
87 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 11);
88 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 3);
89
90 // Copy the next 3 bytes. This should consume the buffer.
91 let bytes = buf_list.copy_to_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]copy_to_bytes().(3);
92 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bytes, &b"llo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
93 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 8);
94 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 2);
95
96 // Copy 6 bytes. This should consume the next buffer.
97 let bytes = buf_list.copy_to_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]copy_to_bytes().(6);
98 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bytes, &b"worldf"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
99 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 2);
100 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 1);
101
102 // Copy the last 2 bytes + this next buffer -- ensure that all buffers are consumed.
103 buf_list.push_chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]push_chunk().(&b"bar"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
104 let bytes = buf_list.copy_to_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]copy_to_bytes().(5);
105 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bytes, &b"oobar"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
106 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(), 0);
107 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf_list.num_chunksrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_chunks().(), 0);
108 }
109 }
110
111 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
112 fn test_iterrust-analyzer cargo buf-list 1.1.2 test_iter().() {
113 let buf_list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![&b"hello"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &b"foo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &b"bar"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().]
114 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
115 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#>();
116
117 // Test iteration over the buf_list.
118 let mut iter = (&buf_list).into_iterrust-analyzer cargo buf-list 1.1.2 imp/impl#[`&'a BufList`][IntoIterator]into_iter().();
119 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", iter);
120 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nextrust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][Iterator]next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"hello"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)));
121 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.size_hintrust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][Iterator]size_hint().(), (3, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)));
122 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.lenrust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][ExactSizeIterator]len().(), 3);
123
124 {
125 let mut iter = iter.clonerust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][Clone]clone().();
126 #[allow(clippy::iter_nth_zero)]
127 {
128 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nthrust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][Iterator]nth().(0), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)));
129 }
130 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.lastrust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][Iterator]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"bar"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)));
131 }
132
133 {
134 let iter = iter.clonerust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][Clone]clone().();
135 let v = iter.foldrust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][Iterator]fold().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |mut v, item| {
136 v.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(item);
137 v
138 });
139 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
140 v,
141 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
142 &Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
143 &Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"foo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
144 &Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"bar"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
145 ]
146 );
147 }
148
149 {
150 let mut iter = iter.clonerust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][Clone]clone().();
151 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.next_backrust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][DoubleEndedIterator]next_back().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"bar"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)));
152 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
153 iter.rfoldrust-analyzer cargo buf-list 1.1.2 imp/impl#[`Iter<'a>`][DoubleEndedIterator]rfold().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |mut v, item| {
154 v.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(item);
155 v
156 }),
157 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
158 &Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"foo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
159 &Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
160 ]
161 );
162 }
163 }
164
165 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
166 fn test_into_iterrust-analyzer cargo buf-list 1.1.2 test_into_iter().() {
167 let buf_list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![&b"hello"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &b"foo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &b"bar"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().]
168 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
169 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#>();
170
171 let into_iter = buf_list.into_iterrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][IntoIterator]into_iter().();
172 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", into_iter);
173 #[allow(clippy::redundant_clone)]
174 let mut into_iter = into_iter.clonerust-analyzer cargo buf-list 1.1.2 imp/impl#[IntoIter][Clone]clone().();
175 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(into_iter.nextrust-analyzer cargo buf-list 1.1.2 imp/impl#[IntoIter][Iterator]next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"hello"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)));
176 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(into_iter.size_hintrust-analyzer cargo buf-list 1.1.2 imp/impl#[IntoIter][Iterator]size_hint().(), (3, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)));
177 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(into_iter.lenrust-analyzer cargo buf-list 1.1.2 imp/impl#[IntoIter][ExactSizeIterator]len().(), 3);
178 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(into_iter.next_backrust-analyzer cargo buf-list 1.1.2 imp/impl#[IntoIter][DoubleEndedIterator]next_back().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]from_static().(&b"bar"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)));
179 }
180
181 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
182 #[should_panic = "`len` (12) greater than remaining (10)"]
183 fn test_copy_to_bytes_panicrust-analyzer cargo buf-list 1.1.2 test_copy_to_bytes_panic().() {
184 let mut buf_list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![&b"hello"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().]
185 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
186 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#>();
187 buf_list.copy_to_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]copy_to_bytes().(12);
188 }