| 1 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::arrayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/; |
| 2 | |
| 3 | use craterust-analyzer cargo memuse 0.2.2 crate/::DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#; |
| 4 | |
| 5 | macro_rules! tuple_implsrust-analyzer cargo memuse 0.2.2 tuple/tuple_impls! { |
| 6 | ($( |
| 7 | $Tuple:ident { |
| 8 | $(($idx:tt) -> $T:ident)+ |
| 9 | } |
| 10 | )+) => { |
| 11 | $( |
| 12 | impl<$($T),+> DynamicUsage for ($($T,)+) where $($T: DynamicUsage),+ |
| 13 | { |
| 14 | fn dynamic_usage(&self) -> usize { |
| 15 | array::IntoIter::new([$(self.$idx.dynamic_usage()),+]).sum::<usize>() |
| 16 | } |
| 17 | |
| 18 | fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) { |
| 19 | array::IntoIter::new([$(self.$idx.dynamic_usage_bounds()),+]) |
| 20 | .fold( |
| 21 | (0, Some(0)), |
| 22 | |(acc_lower, acc_upper), (lower, upper)| { |
| 23 | (acc_lower + lower, acc_upper.zip(upper).map(|(a, b)| a + b)) |
| 24 | }, |
| 25 | ) |
| 26 | } |
| 27 | } |
| 28 | )+ |
| 29 | }; |
| 30 | |
| 31 | () => {}; |
| 32 | } |
| 33 | |
| 34 | tuple_implsrust-analyzer cargo memuse 0.2.2 tuple/tuple_impls!! { |
| 35 | Tuple1 { |
| 36 | (0) -> A |
| 37 | } |
| 38 | Tuple2 { |
| 39 | (0) -> A |
| 40 | (1) -> B |
| 41 | } |
| 42 | Tuple3 { |
| 43 | (0) -> A |
| 44 | (1) -> B |
| 45 | (2) -> C |
| 46 | } |
| 47 | Tuple4 { |
| 48 | (0) -> A |
| 49 | (1) -> B |
| 50 | (2) -> C |
| 51 | (3) -> D |
| 52 | } |
| 53 | Tuple5 { |
| 54 | (0) -> A |
| 55 | (1) -> B |
| 56 | (2) -> C |
| 57 | (3) -> D |
| 58 | (4) -> E |
| 59 | } |
| 60 | Tuple6 { |
| 61 | (0) -> A |
| 62 | (1) -> B |
| 63 | (2) -> C |
| 64 | (3) -> D |
| 65 | (4) -> E |
| 66 | (5) -> F |
| 67 | } |
| 68 | Tuple7 { |
| 69 | (0) -> A |
| 70 | (1) -> B |
| 71 | (2) -> C |
| 72 | (3) -> D |
| 73 | (4) -> E |
| 74 | (5) -> F |
| 75 | (6) -> G |
| 76 | } |
| 77 | Tuple8 { |
| 78 | (0) -> A |
| 79 | (1) -> B |
| 80 | (2) -> C |
| 81 | (3) -> D |
| 82 | (4) -> E |
| 83 | (5) -> F |
| 84 | (6) -> G |
| 85 | (7) -> H |
| 86 | } |
| 87 | Tuple9 { |
| 88 | (0) -> A |
| 89 | (1) -> B |
| 90 | (2) -> C |
| 91 | (3) -> D |
| 92 | (4) -> E |
| 93 | (5) -> F |
| 94 | (6) -> G |
| 95 | (7) -> H |
| 96 | (8) -> I |
| 97 | } |
| 98 | Tuple10 { |
| 99 | (0) -> A |
| 100 | (1) -> B |
| 101 | (2) -> C |
| 102 | (3) -> D |
| 103 | (4) -> E |
| 104 | (5) -> F |
| 105 | (6) -> G |
| 106 | (7) -> H |
| 107 | (8) -> I |
| 108 | (9) -> J |
| 109 | } |
| 110 | Tuple11 { |
| 111 | (0) -> A |
| 112 | (1) -> B |
| 113 | (2) -> C |
| 114 | (3) -> D |
| 115 | (4) -> E |
| 116 | (5) -> F |
| 117 | (6) -> G |
| 118 | (7) -> H |
| 119 | (8) -> I |
| 120 | (9) -> J |
| 121 | (10) -> K |
| 122 | } |
| 123 | Tuple12 { |
| 124 | (0) -> A |
| 125 | (1) -> B |
| 126 | (2) -> C |
| 127 | (3) -> D |
| 128 | (4) -> E |
| 129 | (5) -> F |
| 130 | (6) -> G |
| 131 | (7) -> H |
| 132 | (8) -> I |
| 133 | (9) -> J |
| 134 | (10) -> K |
| 135 | (11) -> L |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | #[cfg(feature = "std")] |
| 140 | #[cfg(test)] |
| 141 | mod testsrust-analyzer cargo memuse 0.2.2 tuple/tests/ { |
| 142 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 143 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#; |
| 144 | |
| 145 | use superrust-analyzer cargo memuse 0.2.2 tuple/::*; |
| 146 | use craterust-analyzer cargo memuse 0.2.2 crate/::hashrust-analyzer cargo memuse 0.2.2 hash/::WIDTHrust-analyzer cargo memuse 0.2.2 hash/WIDTH. as HASH_WIDTHrust-analyzer cargo memuse 0.2.2 hash/WIDTH.; |
| 147 | |
| 148 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 149 | fn tuplesrust-analyzer cargo memuse 0.2.2 tuple/tests/tuples().() { |
| 150 | let a = (0u8, 0u16, 0u32); |
| 151 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(a.dynamic_usagerust-analyzer cargo memuse 0.2.2 tuple/impl#[`(A, B, C)`][DynamicUsage]dynamic_usage().(), 0); |
| 152 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(a.dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 tuple/impl#[`(A, B, C)`][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 153 | |
| 154 | let b = (Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<u8>::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(10), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<u64>::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(2)); |
| 155 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(b.dynamic_usagerust-analyzer cargo memuse 0.2.2 tuple/impl#[`(A, B)`][DynamicUsage]dynamic_usage().(), 26); |
| 156 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(b.dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 tuple/impl#[`(A, B)`][DynamicUsage]dynamic_usage_bounds().(), (26, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(26))); |
| 157 | |
| 158 | let c = ( |
| 159 | HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::<u8>::with_capacityrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]with_capacity().(10), |
| 160 | Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<u64>::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(2), |
| 161 | ); |
| 162 | |
| 163 | // HashSet has capacity 10 -> 16 buckets |
| 164 | let lower_bound = 32 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().HASH_WIDTHrust-analyzer cargo memuse 0.2.2 hash/WIDTH. 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().16; |
| 165 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(c.dynamic_usagerust-analyzer cargo memuse 0.2.2 tuple/impl#[`(A, B)`][DynamicUsage]dynamic_usage().(), lower_bound); |
| 166 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(c.dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 tuple/impl#[`(A, B)`][DynamicUsage]dynamic_usage_bounds().(), (lower_bound, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 167 | } |
| 168 | } |