Debian Codegraph @

src/small_vec_builder.rs

raw symbols SCIP
1 //! A data structure for in place modification of smallvecs.
2 #![deny(missing_docs)]
3 #![allow(dead_code)]
4 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#;
5 use smallvecrust-analyzer cargo smallvec 1.7.0 crate/::{Arrayrust-analyzer cargo smallvec 1.7.0 Array#, SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#};
6
7 /// builds a SmallVec out of itself
8 pub struct InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<'a, A: Arrayrust-analyzer cargo smallvec 1.7.0 Array#> {
9 /// the underlying vector, possibly containing some uninitialized values in the middle!
10 vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v.: &'a mut SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#<A>,
11 /// the end of the target area
12 t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1.: usize,
13 /// the start of the source area
14 s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0.: usize,
15 }
16
17 impl<'a, T: Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, A: Arrayrust-analyzer cargo smallvec 1.7.0 Array#<Itemrust-analyzer cargo smallvec 1.7.0 Array#Item# = T>> Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<'a, A> {
18 fn fmtrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
19 let InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder# { s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0., t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1., vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v. } = self;
20 let s1 = v.lenrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]len().();
21 let cap = v.capacityrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]capacity().();
22 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
23 f,
24 "InPlaceSmallVecBuilder(0..{},{}..{},{})",
25 t1, s0, s1, cap
26 )
27 }
28 }
29
30 /// initializes the source part of this flip buffer with the given vector.
31 /// The target part is initially empty.
32 impl<'a, A: Arrayrust-analyzer cargo smallvec 1.7.0 Array#> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a mut SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#<A>> for InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<'a, A> {
33 fn fromrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`][`From<&'a mut SmallVec<A>>`]from().(value: &'a mut SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#<A>) -> Selfrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`][`From<&'a mut SmallVec<A>>`] {
34 InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder# {
35 vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v.: value,
36 s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0.: 0,
37 t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1.: 0,
38 }
39 }
40 }
41
42 impl<'a, A: Arrayrust-analyzer cargo smallvec 1.7.0 Array#> InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<'a, A> {
43 /// The current target part as a slice
44 pub fn target_slicerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]target_slice().(&self) -> &[A::Itemrust-analyzer cargo smallvec 1.7.0 Array#Item#] {
45 &self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v.[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/RangeTo#self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
46 }
47
48 /// The current source part as a slice
49 pub fn source_slicerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]source_slice().(&self) -> &[A::Itemrust-analyzer cargo smallvec 1.7.0 Array#Item#] {
50 &self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
51 }
52
53 /// The current source part as a slice
54 pub fn source_slice_mutrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]source_slice_mut().(&mut self) -> &mut [A::Itemrust-analyzer cargo smallvec 1.7.0 Array#Item#] {
55 &mut self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().
56 }
57
58 /// ensure that we have at least `capacity` space.
59 #[inline]
60 fn reserverust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]reserve().(&mut self, capacity: usize) {
61 // ensure we have space!
62 if self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().capacity rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. {
63 let v = &mut self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v.;
64 let s0 = self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0.;
65 let s1 = v.lenrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]len().();
66 let sn = s1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().s0;
67 // delegate to the underlying vec for the grow logic
68 v.reserverust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]reserve().(capacity);
69 // move the source to the end of the vec
70 let cap = v.capacityrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]capacity().();
71 // just move source to the end without any concern about dropping
72 unsafe {
73 copyrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/copy().(v.as_mut_ptrrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]as_mut_ptr().(), s0, cap rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().sn, sn);
74 v.set_lenrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]set_len().(cap);
75 }
76 // move s0
77 self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. = cap rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().sn;
78 }
79 }
80
81 /// Take at most `n` elements from `iter` to the target
82 #[inline]
83 pub fn extend_from_iterrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]extend_from_iter().<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = A::Itemrust-analyzer cargo smallvec 1.7.0 Array#Item#>>(&mut self, mut iter: I, n: usize) {
84 if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
85 self.reserverust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]reserve().(n);
86 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n {
87 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
88 self.push_unsaferust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]push_unsafe().(value)
89 }
90 }
91 }
92 }
93
94 /// Push a single value to the target
95 pub fn pushrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]push().(&mut self, value: A::Itemrust-analyzer cargo smallvec 1.7.0 Array#Item#) {
96 // ensure we have space!
97 self.reserverust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]reserve().(1);
98 self.push_unsaferust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]push_unsafe().(value);
99 }
100
101 fn push_unsaferust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]push_unsafe().(&mut self, value: A::Itemrust-analyzer cargo smallvec 1.7.0 Array#Item#) {
102 unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v..as_mut_ptrrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]as_mut_ptr().().addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]add().(self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1.), value) }
103 self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
104 }
105
106 /// Consume `n` elements from the source. If `take` is true they will be added to the target,
107 /// else they will be dropped.
108 #[inline]
109 pub fn consumerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]consume().(&mut self, n: usize, take: bool) {
110 let n = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(n, self.source_slicerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]source_slice().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
111 let v = self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v..as_mut_ptrrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]as_mut_ptr().();
112 if take {
113 if self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. {
114 unsafe {
115 copyrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/copy().(v, self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0., self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1., n);
116 }
117 }
118 self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().n;
119 self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().n;
120 } else {
121 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n {
122 unsafe {
123 self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
124 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::drop_in_placerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/drop_in_place().(v.addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]add().(self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1));
125 }
126 }
127 }
128 }
129
130 /// Skip up to `n` elements from source without adding them to the target.
131 /// They will be immediately dropped!
132 pub fn skiprust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]skip().(&mut self, n: usize) {
133 let n = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(n, self.source_slicerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]source_slice().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
134 let v = self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v..as_mut_ptrrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]as_mut_ptr().();
135 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n {
136 unsafe {
137 self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
138 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::drop_in_placerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/drop_in_place().(v.addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]add().(self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1));
139 }
140 }
141 }
142
143 /// Take up to `n` elements from source to target.
144 /// If n is larger than the size of the remaining source, this will only copy all remaining elements in source.
145 pub fn takerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]take().(&mut self, n: usize) {
146 let n = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(n, self.source_slicerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]source_slice().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
147 if self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. {
148 unsafe {
149 copyrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/copy().(self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v..as_mut_ptrrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]as_mut_ptr().(), self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0., self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1., n);
150 }
151 }
152 self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().n;
153 self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().n;
154 }
155
156 /// Takes the next element from the source, if it exists
157 pub fn pop_frontrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]pop_front().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<A::Itemrust-analyzer cargo smallvec 1.7.0 Array#Item#> {
158 if self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v..lenrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]len().() {
159 self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
160 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/read().(self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v..as_ptrrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]as_ptr().().addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]add().(self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1)) })
161 } else {
162 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
163 }
164 }
165
166 fn drop_sourcerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]drop_source().(&mut self) {
167 // use truncate to get rid of the source part, if any, calling drop as needed
168 self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v..truncaterust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]truncate().(self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0.);
169 // use set_len to get rid of the gap part between t1 and s0, not calling drop!
170 unsafe {
171 self.vrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#v..set_lenrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]set_len().(self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1.);
172 }
173 self.s0rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#s0. = self.t1rust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#t1.;
174 // shorten the source part
175 }
176 }
177
178 #[inline]
179 unsafe fn copyrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/copy().<T>(v: *mut T, from: usize, to: usize, n: usize) {
180 // if to < from {
181 // for i in 0..n {
182 // std::ptr::write(v.add(to + i), std::ptr::read(v.add(from + i)));
183 // }
184 // } else {
185 // for i in (0..n).rev() {
186 // std::ptr::write(v.add(to + i), std::ptr::read(v.add(from + i)));
187 // }
188 // }
189 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy().(v.addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]add().(from), v.addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]add().(to), n);
190 }
191
192 /// the purpose of drop is to clean up and make the SmallVec that we reference into a normal
193 /// SmallVec again.
194 impl<'a, A: Arrayrust-analyzer cargo smallvec 1.7.0 Array#> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<'a, A> {
195 fn droprust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`][Drop]drop().(&mut self) {
196 // drop the source part.
197 self.drop_sourcerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]drop_source().();
198 }
199 }
200
201 #[cfg(test)]
202 mod testsrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/ {
203 extern crate testdroprust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/testdrop/;
204 use superrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/::*;
205 use testdroprust-analyzer cargo testdrop 0.1.2 crate/::{Itemrust-analyzer cargo testdrop 0.1.2 Item#, TestDroprust-analyzer cargo testdrop 0.1.2 TestDrop#};
206
207 type Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#<'a> = [Itemrust-analyzer cargo testdrop 0.1.2 Item#<'a>; 2];
208
209 fn everything_droppedrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/everything_dropped().<'a, F>(td: &'a TestDroprust-analyzer cargo testdrop 0.1.2 TestDrop#, n: usize, f: F)
210 where
211 F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#<'a>>, SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#<'a>>),
212 {
213 let mut a: SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#<'a>> = SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#::newrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]new().();
214 let mut b: SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#<'a>> = SmallVecrust-analyzer cargo smallvec 1.7.0 SmallVec#::newrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]new().();
215 let mut ids: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
216 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n {
217 let (id, item) = td.new_itemrust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]new_item().();
218 a.pushrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]push().(item);
219 ids.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(id);
220 }
221 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n {
222 let (id, item) = td.new_itemrust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]new_item().();
223 b.pushrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`]push().(item);
224 ids.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(id);
225 }
226 f(a, b);
227 for id in ids {
228 td.assert_droprust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]assert_drop().(id);
229 }
230 }
231
232 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
233 fn drop_just_sourcerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/drop_just_source().() {
234 everything_droppedrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/everything_dropped().(&TestDroprust-analyzer cargo testdrop 0.1.2 TestDrop#::newrust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]new().(), 10, |mut a, _| {
235 let _: InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#> = (&mut a).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
236 })
237 }
238
239 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
240 fn target_push_gaprust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/target_push_gap().() {
241 everything_droppedrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/everything_dropped().(&TestDroprust-analyzer cargo testdrop 0.1.2 TestDrop#::newrust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]new().(), 10, |mut a, b| {
242 let mut res: InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#> = (&mut a).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
243 for x in b.into_iterrust-analyzer cargo smallvec 1.7.0 impl#[`SmallVec<A>`][IntoIterator]into_iter().() {
244 res.pushrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]push().(x);
245 }
246 })
247 }
248
249 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
250 fn source_move_somerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/source_move_some().() {
251 everything_droppedrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/everything_dropped().(&TestDroprust-analyzer cargo testdrop 0.1.2 TestDrop#::newrust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]new().(), 10, |mut a, _| {
252 let mut res: InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#> = (&mut a).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
253 res.takerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]take().(3);
254 })
255 }
256
257 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
258 fn source_move_allrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/source_move_all().() {
259 everything_droppedrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/everything_dropped().(&TestDroprust-analyzer cargo testdrop 0.1.2 TestDrop#::newrust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]new().(), 10, |mut a, _| {
260 let mut res: InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#> = (&mut a).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
261 res.takerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]take().(10);
262 })
263 }
264
265 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
266 fn source_drop_somerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/source_drop_some().() {
267 everything_droppedrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/everything_dropped().(&TestDroprust-analyzer cargo testdrop 0.1.2 TestDrop#::newrust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]new().(), 10, |mut a, _| {
268 let mut res: InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#> = (&mut a).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
269 res.skiprust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]skip().(3);
270 })
271 }
272
273 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
274 fn source_drop_allrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/source_drop_all().() {
275 everything_droppedrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/everything_dropped().(&TestDroprust-analyzer cargo testdrop 0.1.2 TestDrop#::newrust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]new().(), 10, |mut a, _| {
276 let mut res: InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#> = (&mut a).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
277 res.skiprust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]skip().(10);
278 })
279 }
280
281 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
282 fn source_pop_somerust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/source_pop_some().() {
283 everything_droppedrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/everything_dropped().(&TestDroprust-analyzer cargo testdrop 0.1.2 TestDrop#::newrust-analyzer cargo testdrop 0.1.2 impl#[TestDrop]new().(), 10, |mut a, _| {
284 let mut res: InPlaceSmallVecBuilderrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/InPlaceSmallVecBuilder#<Arrayrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/tests/Array#> = (&mut a).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
285 res.pop_frontrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]pop_front().();
286 res.pop_frontrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]pop_front().();
287 res.pop_frontrust-analyzer cargo inplace-vec-builder 0.1.1 small_vec_builder/impl#[`InPlaceSmallVecBuilder<'a, A>`]pop_front().();
288 })
289 }
290 }