| 1 | //! Measure dynamic memory usage of your types! |
| 2 | //! |
| 3 | //! ## About |
| 4 | //! |
| 5 | //! Memory-tracking is a common activity in large applications, particularly ones |
| 6 | //! that receive data from a network and store it in memory. By monitoring how much |
| 7 | //! memory is used by different areas of the application, memory pressure can be |
| 8 | //! alleviated by ignoring new packets, or implementing random drop logic for DoS |
| 9 | //! mitigation. |
| 10 | //! |
| 11 | //! Measuring memory use on the stack is easy, with [`std::mem::size_of`] and |
| 12 | //! friends. Measuring memory allocated on the heap is more tricky. Applications can |
| 13 | //! use a custom global allocator to track the memory usage of different areas. This |
| 14 | //! isn't an option for reusable library code however, and the nearest alternative |
| 15 | //! (using custom allocators for individual types) is currently only an experimental |
| 16 | //! feature in nightly Rust ([`allocator_api`]). |
| 17 | //! |
| 18 | //! [`allocator_api`]: https://github.com/rust-lang/rust/issues/32838 |
| 19 | //! |
| 20 | //! This crate takes a different approach: it provides traits that library authors |
| 21 | //! can use to expose dynamic memory usage information on their types. By composing |
| 22 | //! these implementations, we gain the ability to query the amount of heap-allocated |
| 23 | //! memory in use by specific instances of types at any point in time, without any |
| 24 | //! changes to the way in which these types are constructed. |
| 25 | //! |
| 26 | //! ## Minimum Supported Rust Version |
| 27 | //! |
| 28 | //! Requires Rust **1.51** or newer. |
| 29 | //! |
| 30 | //! In the future, we reserve the right to change MSRV (i.e. MSRV is out-of-scope for this |
| 31 | //! crate's SemVer guarantees), however when we do it will be accompanied by a minor |
| 32 | //! version bump. |
| 33 | //! |
| 34 | //! ## Usage |
| 35 | //! |
| 36 | //! ``` |
| 37 | //! # #[cfg(feature = "std")] |
| 38 | //! # { |
| 39 | //! # use std::collections::HashMap; |
| 40 | //! use memuse::DynamicUsage; |
| 41 | //! |
| 42 | //! // Simple types don't allocate memory on the heap. |
| 43 | //! assert_eq!(7u64.dynamic_usage(), 0); |
| 44 | //! assert_eq!("I'm simple!".dynamic_usage(), 0); |
| 45 | //! |
| 46 | //! // When a type allocates memory, we can see it! |
| 47 | //! assert_eq!(vec![7u64; 2].dynamic_usage(), 16); |
| 48 | //! |
| 49 | //! // We see the memory the type has allocated, even if it isn't being used. |
| 50 | //! let empty: Vec<u32> = Vec::with_capacity(100); |
| 51 | //! assert_eq!(empty.len(), 0); |
| 52 | //! assert_eq!(empty.dynamic_usage(), 400); |
| 53 | //! |
| 54 | //! // For some types, we can't measure the exact memory usage, so we return a best |
| 55 | //! // estimate. If you need precision, call `dynamic_usage_bounds` which returns a |
| 56 | //! // lower bound, and (if known) an upper bound. |
| 57 | //! let map: HashMap<u8, u64> = HashMap::with_capacity(27); |
| 58 | //! let (lower, upper): (usize, Option<usize>) = map.dynamic_usage_bounds(); |
| 59 | //! assert!(upper.is_none()); |
| 60 | //! # } |
| 61 | //! ``` |
| 62 | |
| 63 | #![no_std] |
| 64 | #![forbid(unsafe_code)] |
| 65 | // Catch documentation errors caused by code changes. |
| 66 | #![deny(broken_intra_doc_links)] |
| 67 | |
| 68 | #[cfg_attr(test, macro_use)] |
| 69 | extern crate allocrust-analyzer cargo memuse 0.2.2 alloc/; |
| 70 | |
| 71 | #[cfg(feature = "std")] |
| 72 | extern crate stdrust-analyzer cargo memuse 0.2.2 std/; |
| 73 | |
| 74 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::boxedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/::Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#; |
| 75 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::{BinaryHeaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/binary_heap/BinaryHeap#, LinkedListrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/LinkedList#, VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#}; |
| 76 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 77 | 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#; |
| 78 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/; |
| 79 | |
| 80 | /// Trait for measuring the dynamic memory usage of types. |
| 81 | pub trait DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage# { |
| 82 | /// Returns a best estimate of the amount of heap-allocated memory used by this type. |
| 83 | /// |
| 84 | /// For most types, this will return an exact value. However, for types that use a |
| 85 | /// complex allocation strategy (such as a `HashMap`), `memuse` cannot provide an |
| 86 | /// exact heap allocation value, as it does not have access to the internal details |
| 87 | /// and can only infer allocations from observable properties (such as the number of |
| 88 | /// elements in a collection, or constants extracted from the implementation of the |
| 89 | /// type). In those cases, this method returns a "best estimate" inferred from the |
| 90 | /// implemented behaviour of the type. As more crates implement this trait themselves, |
| 91 | /// the estimates will become more precise. |
| 92 | /// |
| 93 | /// The value returned by this method will always fall between the bounds returned by |
| 94 | /// [`DynamicUsage::dynamic_usage_bounds`]: |
| 95 | /// |
| 96 | /// ``` |
| 97 | /// # #[cfg(feature = "std")] |
| 98 | /// # { |
| 99 | /// use std::collections::HashMap; |
| 100 | /// use memuse::DynamicUsage; |
| 101 | /// |
| 102 | /// let a: HashMap<u8, u64> = HashMap::with_capacity(27); |
| 103 | /// let usage = a.dynamic_usage(); |
| 104 | /// let (lower, upper) = a.dynamic_usage_bounds(); |
| 105 | /// |
| 106 | /// assert!(lower <= usage); |
| 107 | /// if let Some(upper) = upper { |
| 108 | /// assert!(usage <= upper); |
| 109 | /// } |
| 110 | /// # } |
| 111 | /// ``` |
| 112 | fn dynamic_usagerust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage().(&self) -> usize; |
| 113 | |
| 114 | /// Returns the lower and upper bounds on the amount of heap-allocated memory used by |
| 115 | /// this type. |
| 116 | /// |
| 117 | /// The lower bound is always precise; a type cannot allocate fewer than zero bytes, |
| 118 | /// and a collection cannot allocate fewer than the number of bytes required to store |
| 119 | /// the entries it holds. |
| 120 | /// |
| 121 | /// The upper bound is only present if some property of the type ensures that its |
| 122 | /// allocations do not exceed the bound, and is `None` otherwise (to indicate an |
| 123 | /// unlimited upper bound). |
| 124 | /// |
| 125 | /// If the type's allocated memory is precisely known, then the lower and upper bounds |
| 126 | /// will be equal. |
| 127 | fn dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage_bounds().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>); |
| 128 | } |
| 129 | |
| 130 | // |
| 131 | // Helper macros |
| 132 | // |
| 133 | |
| 134 | /// Helper to implement [`DynamicUsage`] for simple types that don't allocate. |
| 135 | /// |
| 136 | /// # Examples |
| 137 | /// |
| 138 | /// ``` |
| 139 | /// // Must be imported so it is accessible to the macro. |
| 140 | /// use memuse::DynamicUsage; |
| 141 | /// |
| 142 | /// struct RegisterByte(u8); |
| 143 | /// struct RegisterWord(u16); |
| 144 | /// |
| 145 | /// memuse::impl_no_dynamic_usage!(RegisterByte, RegisterWord); |
| 146 | /// ``` |
| 147 | /// |
| 148 | /// The above is equivalent to: |
| 149 | /// ``` |
| 150 | /// use memuse::DynamicUsage; |
| 151 | /// |
| 152 | /// struct RegisterByte(u8); |
| 153 | /// struct RegisterWord(u16); |
| 154 | /// |
| 155 | /// impl DynamicUsage for RegisterByte { |
| 156 | /// #[inline(always)] |
| 157 | /// fn dynamic_usage(&self) -> usize { |
| 158 | /// 0 |
| 159 | /// } |
| 160 | /// |
| 161 | /// #[inline(always)] |
| 162 | /// fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) { |
| 163 | /// (0, Some(0)) |
| 164 | /// } |
| 165 | /// } |
| 166 | /// |
| 167 | /// impl DynamicUsage for RegisterWord { |
| 168 | /// #[inline(always)] |
| 169 | /// fn dynamic_usage(&self) -> usize { |
| 170 | /// 0 |
| 171 | /// } |
| 172 | /// |
| 173 | /// #[inline(always)] |
| 174 | /// fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) { |
| 175 | /// (0, Some(0)) |
| 176 | /// } |
| 177 | /// } |
| 178 | /// ``` |
| 179 | #[macro_export] |
| 180 | macro_rules! impl_no_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_no_dynamic_usage! { |
| 181 | ($($type:ty),+) => { |
| 182 | $( |
| 183 | impl DynamicUsage for $type { |
| 184 | #[inline(always)] |
| 185 | fn dynamic_usage(&self) -> usize { |
| 186 | 0 |
| 187 | } |
| 188 | |
| 189 | #[inline(always)] |
| 190 | fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) { |
| 191 | (0, Some(0)) |
| 192 | } |
| 193 | } |
| 194 | )+ |
| 195 | }; |
| 196 | } |
| 197 | |
| 198 | macro_rules! impl_iterable_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_iterable_dynamic_usage! { |
| 199 | ($type:ty, $base_usage:expr) => { |
| 200 | impl<T: DynamicUsage> DynamicUsage for $type { |
| 201 | fn dynamic_usage(&self) -> usize { |
| 202 | $base_usage(self) + self.iter().map(DynamicUsage::dynamic_usage).sum::<usize>() |
| 203 | } |
| 204 | |
| 205 | fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) { |
| 206 | let base = $base_usage(self); |
| 207 | let (lower, upper) = self.iter().map(DynamicUsage::dynamic_usage_bounds).fold( |
| 208 | (0, Some(0)), |
| 209 | |(acc_lower, acc_upper), (lower, upper)| { |
| 210 | (acc_lower + lower, acc_upper.zip(upper).map(|(a, b)| a + b)) |
| 211 | }, |
| 212 | ); |
| 213 | (base + lower, upper.map(|u| base + u)) |
| 214 | } |
| 215 | } |
| 216 | }; |
| 217 | } |
| 218 | |
| 219 | // |
| 220 | // Primitives |
| 221 | // |
| 222 | |
| 223 | impl_no_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_no_dynamic_usage!!(()); |
| 224 | impl_no_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_no_dynamic_usage!!(i8, i16, i32, i64, i128, isize); |
| 225 | impl_no_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_no_dynamic_usage!!(u8, u16, u32, u64, u128, usize); |
| 226 | impl_no_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_no_dynamic_usage!!(f32, f64, bool); |
| 227 | impl_no_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_no_dynamic_usage!!(char, str); |
| 228 | |
| 229 | // Tuples are handled below (so they render more nicely in docs) |
| 230 | |
| 231 | impl<T: DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#, const N: usize> DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage# for [T; N] { |
| 232 | fn dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[`[T; N]`][DynamicUsage]dynamic_usage().(&self) -> usize { |
| 233 | self.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#::dynamic_usagerust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage().).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().::<usize>() |
| 234 | } |
| 235 | |
| 236 | fn dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[`[T; N]`][DynamicUsage]dynamic_usage_bounds().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 237 | self.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#::dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage_bounds().).foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]fold().( |
| 238 | (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0)), |
| 239 | |(acc_lower, acc_upper), (lower, upper)| { |
| 240 | (acc_lower 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().lower, acc_upper.ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]zip().(upper).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(a, b)| a 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().b)) |
| 241 | }, |
| 242 | ) |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | impl_iterable_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_iterable_dynamic_usage!!([T], |_| 0); |
| 247 | |
| 248 | // |
| 249 | // Structs |
| 250 | // |
| 251 | |
| 252 | impl DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage# for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 253 | fn dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[String][DynamicUsage]dynamic_usage().(&self) -> usize { |
| 254 | self.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]capacity().() |
| 255 | } |
| 256 | |
| 257 | fn dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[String][DynamicUsage]dynamic_usage_bounds().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 258 | let usage = self.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]capacity().(); |
| 259 | (usage, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(usage)) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // |
| 264 | // Containers |
| 265 | // |
| 266 | |
| 267 | impl<T: DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#> DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage# for Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<T> { |
| 268 | fn dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[`Box<T>`][DynamicUsage]dynamic_usage().(&self) -> usize { |
| 269 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>() 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().self.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsRef<T>`]as_ref().().dynamic_usagerust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage().() |
| 270 | } |
| 271 | |
| 272 | fn dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[`Box<T>`][DynamicUsage]dynamic_usage_bounds().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 273 | let box_size = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>(); |
| 274 | let (inner_lower, inner_upper) = self.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsRef<T>`]as_ref().().dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage_bounds().(); |
| 275 | (box_size 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().inner_lower, inner_upper.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|u| box_size 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().u)) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | impl<T: DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#> DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage# for Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> { |
| 280 | fn dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[`Option<T>`][DynamicUsage]dynamic_usage().(&self) -> usize { |
| 281 | self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#::dynamic_usagerust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage().).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0) |
| 282 | } |
| 283 | |
| 284 | fn dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[`Option<T>`][DynamicUsage]dynamic_usage_bounds().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 285 | self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() |
| 286 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#::dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage_bounds().) |
| 287 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().((0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))) |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | impl<T: DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#, E: DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage#> DynamicUsagerust-analyzer cargo memuse 0.2.2 DynamicUsage# for Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E> { |
| 292 | fn dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[`Result<T, E>`][DynamicUsage]dynamic_usage().(&self) -> usize { |
| 293 | match self { |
| 294 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(t) => t.dynamic_usagerust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage().(), |
| 295 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => e.dynamic_usagerust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage().(), |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | fn dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[`Result<T, E>`][DynamicUsage]dynamic_usage_bounds().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 300 | match self { |
| 301 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(t) => t.dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage_bounds().(), |
| 302 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => e.dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 DynamicUsage#dynamic_usage_bounds().(), |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // |
| 308 | // Collections |
| 309 | // |
| 310 | |
| 311 | impl_iterable_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_iterable_dynamic_usage!!(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>, |c: &Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>| c.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().() *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>()); |
| 312 | |
| 313 | impl_iterable_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_iterable_dynamic_usage!!(BinaryHeaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/binary_heap/BinaryHeap#<T>, |c: &BinaryHeaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/binary_heap/BinaryHeap#<T>| { |
| 314 | // BinaryHeap<T> is a wrapper around Vec<T> |
| 315 | c.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/binary_heap/impl#[`BinaryHeap<T, A>`]capacity().() *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>() |
| 316 | }); |
| 317 | |
| 318 | impl_iterable_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_iterable_dynamic_usage!!(LinkedListrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/LinkedList#<T>, |c: &LinkedListrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/LinkedList#<T>| { |
| 319 | c.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/impl#[`LinkedList<T, A>`]len().() *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>() |
| 320 | }); |
| 321 | |
| 322 | impl_iterable_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_iterable_dynamic_usage!!(VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<T>, |c: &VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<T>| { |
| 323 | // +1 since the ringbuffer always leaves one space empty. |
| 324 | (c.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]capacity().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1) *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>() |
| 325 | }); |
| 326 | |
| 327 | #[cfg(feature = "std")] |
| 328 | mod hashrust-analyzer cargo memuse 0.2.2 hash/; |
| 329 | |
| 330 | // |
| 331 | // External crate types (provided for helpfulness, since `DynamicUsage` can only be |
| 332 | // implemented either here or in the external crate). |
| 333 | // |
| 334 | |
| 335 | #[cfg(feature = "nonempty")] |
| 336 | impl_iterable_dynamic_usagerust-analyzer cargo memuse 0.2.2 impl_iterable_dynamic_usage!!(nonemptyrust-analyzer cargo nonempty 0.11.0 crate/::NonEmptyrust-analyzer cargo nonempty 0.11.0 NonEmpty#<T>, |c: &nonemptyrust-analyzer cargo nonempty 0.11.0 crate/::NonEmptyrust-analyzer cargo nonempty 0.11.0 NonEmpty#<T>| { |
| 337 | // NonEmpty<T> stores its head element separately from its tail Vec<T>. |
| 338 | (c.capacityrust-analyzer cargo nonempty 0.11.0 impl#[`NonEmpty<T>`]capacity().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1) *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>() |
| 339 | }); |
| 340 | |
| 341 | // |
| 342 | // Larger definitions (placed at the end so they render more nicely in docs). |
| 343 | // |
| 344 | |
| 345 | mod tuplerust-analyzer cargo memuse 0.2.2 tuple/; |
| 346 | |
| 347 | #[cfg(test)] |
| 348 | mod testsrust-analyzer cargo memuse 0.2.2 tests/ { |
| 349 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::ToStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/ToString#; |
| 350 | |
| 351 | use superrust-analyzer cargo memuse 0.2.2 crate/::*; |
| 352 | |
| 353 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 354 | fn standard_typesrust-analyzer cargo memuse 0.2.2 tests/standard_types().() { |
| 355 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(129u8.dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[u8][DynamicUsage]dynamic_usage().(), 0); |
| 356 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(3i128.dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[i128][DynamicUsage]dynamic_usage().(), 0); |
| 357 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(7.0f32.dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[f32][DynamicUsage]dynamic_usage().(), 0); |
| 358 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foobar".dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[str][DynamicUsage]dynamic_usage().(), 0); |
| 359 | |
| 360 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(129u8.dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[u8][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 361 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(3i128.dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[i128][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 362 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(7.0f32.dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[f32][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 363 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foobar".dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[str][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 364 | } |
| 365 | |
| 366 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 367 | fn stringrust-analyzer cargo memuse 0.2.2 tests/string().() { |
| 368 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().().dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[String][DynamicUsage]dynamic_usage().(), 0); |
| 369 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foobar".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().dynamic_usagerust-analyzer cargo memuse 0.2.2 impl#[String][DynamicUsage]dynamic_usage().(), 6); |
| 370 | |
| 371 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().().dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[String][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 372 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foobar".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().dynamic_usage_boundsrust-analyzer cargo memuse 0.2.2 impl#[String][DynamicUsage]dynamic_usage_bounds().(), (6, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(6))); |
| 373 | } |
| 374 | |
| 375 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 376 | fn boxedrust-analyzer cargo memuse 0.2.2 tests/boxed().() { |
| 377 | let a: u64 = 7; |
| 378 | 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 impl#[u64][DynamicUsage]dynamic_usage().(), 0); |
| 379 | 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 impl#[u64][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 380 | |
| 381 | let b: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<u64> = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(42); |
| 382 | 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 impl#[`Box<T>`][DynamicUsage]dynamic_usage().(), 8); |
| 383 | 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 impl#[`Box<T>`][DynamicUsage]dynamic_usage_bounds().(), (8, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(8))); |
| 384 | |
| 385 | let capacity = 7; |
| 386 | let c: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u16>> = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity)); |
| 387 | let expected = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u16>>() 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 ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<u16>(); |
| 388 | 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 impl#[`Box<T>`][DynamicUsage]dynamic_usage().(), expected); |
| 389 | 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 impl#[`Box<T>`][DynamicUsage]dynamic_usage_bounds().(), (expected, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected))); |
| 390 | } |
| 391 | |
| 392 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 393 | fn optionrust-analyzer cargo memuse 0.2.2 tests/option().() { |
| 394 | let a: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 395 | let b: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![7u8; 4]); |
| 396 | 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 impl#[`Option<T>`][DynamicUsage]dynamic_usage().(), 0); |
| 397 | 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 impl#[`Option<T>`][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 398 | 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 impl#[`Option<T>`][DynamicUsage]dynamic_usage().(), 4); |
| 399 | 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 impl#[`Option<T>`][DynamicUsage]dynamic_usage_bounds().(), (4, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4))); |
| 400 | } |
| 401 | |
| 402 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 403 | fn arrayrust-analyzer cargo memuse 0.2.2 tests/array().() { |
| 404 | let a = [7; 42]; |
| 405 | 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 impl#[`[T; N]`][DynamicUsage]dynamic_usage().(), 0); |
| 406 | 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 impl#[`[T; N]`][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 407 | |
| 408 | let mut b = [Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#]; |
| 409 | 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 impl#[`[T; N]`][DynamicUsage]dynamic_usage().(), 0); |
| 410 | 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 impl#[`[T; N]`][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 411 | |
| 412 | b[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut(). = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![4u8; 20]); |
| 413 | 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 impl#[`[T; N]`][DynamicUsage]dynamic_usage().(), 20); |
| 414 | 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 impl#[`[T; N]`][DynamicUsage]dynamic_usage_bounds().(), (20, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(20))); |
| 415 | } |
| 416 | |
| 417 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 418 | fn vecrust-analyzer cargo memuse 0.2.2 tests/vec().() { |
| 419 | let capacity = 7; |
| 420 | let mut a = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity); |
| 421 | a.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(42u64); |
| 422 | |
| 423 | let expected = capacity rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<u64>(); |
| 424 | 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 impl#[`Vec<T>`][DynamicUsage]dynamic_usage().(), expected); |
| 425 | 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 impl#[`Vec<T>`][DynamicUsage]dynamic_usage_bounds().(), (expected, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected))); |
| 426 | } |
| 427 | |
| 428 | #[cfg(feature = "nonempty")] |
| 429 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 430 | fn nonemptyrust-analyzer cargo memuse 0.2.2 tests/nonempty().() { |
| 431 | let a = nonemptyrust-analyzer cargo nonempty 0.11.0 crate/::NonEmptyrust-analyzer cargo nonempty 0.11.0 NonEmpty#::newrust-analyzer cargo nonempty 0.11.0 impl#[`NonEmpty<T>`]new().(42); |
| 432 | 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 impl#[`nonempty::NonEmpty<T>`][DynamicUsage]dynamic_usage().(), 0); |
| 433 | 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 impl#[`nonempty::NonEmpty<T>`][DynamicUsage]dynamic_usage_bounds().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 434 | |
| 435 | const CAPACITYrust-analyzer cargo memuse 0.2.2 tests/CAPACITY.: usize = 7; |
| 436 | let b = nonemptyrust-analyzer cargo nonempty 0.11.0 crate/::NonEmptyrust-analyzer cargo nonempty 0.11.0 NonEmpty#::from_slicerust-analyzer cargo nonempty 0.11.0 impl#[`NonEmpty<T>`]from_slice().(&[27u128; CAPACITYrust-analyzer cargo memuse 0.2.2 tests/CAPACITY.]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 437 | |
| 438 | let expected = (CAPACITYrust-analyzer cargo memuse 0.2.2 tests/CAPACITY. 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) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<u128>(); |
| 439 | 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 impl#[`nonempty::NonEmpty<T>`][DynamicUsage]dynamic_usage().(), expected); |
| 440 | 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 impl#[`nonempty::NonEmpty<T>`][DynamicUsage]dynamic_usage_bounds().(), (expected, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected))); |
| 441 | } |
| 442 | } |