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