Repository: paritytech/substrate
File: primitives/weights/src/weight_meter.rs (Rust)

Code before:
		time.max(pov)
	}

	/// Consume some weight and defensively fail if it is over the limit. Saturate in any case.
	#[deprecated(note = "Use `consume` instead. Will be removed after December 2023.")]
	pub fn defensive_saturating_accrue(&mut self, w: Weight) {
		self.consume(w);
	}

	/// Consume some weight and defensively fail if it is over the limit. Saturate in any case.
	///
	/// This is provided as a less noisy version of `defensive_saturating_accrue`.
	pub fn consume(&mut self, w: Weight) {
		self.consumed.saturating_accrue(w);
		debug_assert!(self.consumed.all_lte(self.limit), "Weight counter overflow");
	}

	/// Consume the given weight after checking that it can be consumed and return `true`. Otherwise
	/// do nothing and return `false`.
	#[deprecated(note = "Use `try_consume` instead. Will be removed after December 2023.")]
	pub fn check_accrue(&mut self, w: Weight) -> bool {
		self.try_consume(w).is_ok()
	}

	/// Consume the given weight after checking that it can be consumed and return `Ok`. Otherwise
	/// do nothing and return `Err`.
	pub fn try_consume(&mut self, w: Weight) -> Result<(), ()> {
		self.consumed.checked_add(&w).map_or(Err(()), |test| {
			if test.any_gt(self.limit) {
				Err(())
			} else {
				self.consumed = test;
				Ok(())
			}
		})
	}

	/// Check if the given weight can be consumed.
	#[deprecated(note = "Use `can_consume` instead. Will be removed after December 2023.")]
	pub fn can_accrue(&self, w: Weight) -> bool {
		self.consumed.checked_add(&w).map_or(false, |t| t.all_lte(self.limit))
	}

	/// Check if the given weight can be consumed.
	pub fn can_consume(&self, w: Weight) -> bool {
		self.consumed.checked_add(&w).map_or(false, |t| t.all_lte(self.limit))
	}
}

#[cfg(test)]
mod tests {

Review comment (suggestion):
```suggestion
	/// Consume the given weight after checking that it can be consumed.
	///
	/// Returns `Ok` if the weight can be consumed or otherwise an `Err`.
```

Code after:
		time.max(pov)
	}

	/// Consume some weight and defensively fail if it is over the limit. Saturate in any case.
	#[deprecated(note = "Use `consume` instead. Will be removed after December 2023.")]
	pub fn defensive_saturating_accrue(&mut self, w: Weight) {
		self.consume(w);
	}

	/// Consume some weight and defensively fail if it is over the limit. Saturate in any case.
	pub fn consume(&mut self, w: Weight) {
		self.consumed.saturating_accrue(w);
		debug_assert!(self.consumed.all_lte(self.limit), "Weight counter overflow");
	}

	/// Consume the given weight after checking that it can be consumed and return `true`. Otherwise
	/// do nothing and return `false`.
	#[deprecated(note = "Use `try_consume` instead. Will be removed after December 2023.")]
	pub fn check_accrue(&mut self, w: Weight) -> bool {
		self.try_consume(w).is_ok()
	}

	/// Consume the given weight after checking that it can be consumed.
	///
	/// Returns `Ok` if the weight can be consumed or otherwise an `Err`.
	pub fn try_consume(&mut self, w: Weight) -> Result<(), ()> {
		self.consumed.checked_add(&w).map_or(Err(()), |test| {
			if test.any_gt(self.limit) {
				Err(())
			} else {
				self.consumed = test;
				Ok(())
			}
		})
	}

	/// Check if the given weight can be consumed.
	#[deprecated(note = "Use `can_consume` instead. Will be removed after December 2023.")]
	pub fn can_accrue(&self, w: Weight) -> bool {
		self.can_consume(w)
	}

	/// Check if the given weight can be consumed.
	pub fn can_consume(&self, w: Weight) -> bool {
		self.consumed.checked_add(&w).map_or(false, |t| t.all_lte(self.limit))
	}
}

#[cfg(test)]
mod tests {
	use crate::*;