Skip to content

Commit

Permalink
Document cmp_range()
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Dec 9, 2024
1 parent 00bd033 commit 821df55
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/cmp_range.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use std::cmp::Ordering;

/// Compares `value` to `lower` and `upper`, where `lower <= upper`, and
/// reports on where `value` falls with respect to the range.
///
/// See [`RangeOrdering`] for the recognized possibilities.
///
/// # Panics
///
/// Panics if `lower > upper`
Expand All @@ -19,13 +24,20 @@ pub fn cmp_range<T: Ord + std::fmt::Debug>(value: T, lower: T, upper: T) -> Rang
}
}

/// Return type of [`cmp_range()`]
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum RangeOrdering {
/// Returned when `value` is less than `lower`
Less,
/// Returned when `value` equals `lower` and is less than `upper`
EqLower,
/// Returned when `value` is between `lower` and `upper`
Between,
/// Returned when `value` equals both `lower` and `upper`
EqBoth,
/// Returned when `value` equals `upper` and is greater than `lower`
EqUpper,
/// Returned when `value` is greater than `upper`
Greater,
}

Expand Down

0 comments on commit 821df55

Please sign in to comment.