Set a new limit. Clamps count if necessary.
(&mut self, new_limit: u32)
| 112 | } |
| 113 | |
| 114 | let current_count = self.count; |
| 115 | let potential_count = if amount > u32::MAX - current_count { |
| 116 | u32::MAX |
| 117 | } else { |
| 118 | current_count + amount |
| 119 | }; |
| 120 | |
| 121 | if potential_count >= self.limit { |
| 122 | // Clamp to limit |
| 123 | self.count = self.limit; |