Skip to content

Commit

Permalink
One clone less in constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicceboy committed Sep 4, 2024
1 parent 8f8eda6 commit 73ab9f6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/types/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,21 @@ impl<T: num_traits::WrappingSub<Output = T> + num_traits::SaturatingAdd<Output =
}
}

impl<T: core::ops::Sub<Output = T> + core::fmt::Debug + Default + Clone + PartialOrd> Bounded<T> {
impl<T: core::ops::Sub<Output = T> + core::fmt::Debug + Default + core::cmp::PartialOrd> Bounded<T>
where
for<'a> &'a T: core::ops::Sub<Output = T>,
{
/// Returns the effective value which is either the number, or the positive
/// offset of that number from the start of the value range. `Either::Left`
/// represents the positive offset, and `Either::Right` represents
/// the number.
pub fn effective_value(&self, value: T) -> either::Either<T, T> {
match &self {
match self {
Self::Range {
start: Some(start), ..
} => {
debug_assert!(&value >= start);
either::Left(value - start.clone())
either::Left(&value - start)
}
_ => either::Right(value),
}
Expand Down

0 comments on commit 73ab9f6

Please sign in to comment.