Skip to content

Commit

Permalink
chore: add From<RangeInclusive<>> impl for RankRange
Browse files Browse the repository at this point in the history
  • Loading branch information
malandis committed Feb 5, 2025
1 parent cf2604b commit d749551
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/leaderboard/messages/data/fetch_by_rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ impl From<Range<u32>> for RankRange {
}
}

impl From<std::ops::RangeInclusive<u32>> for RankRange {
/// Converts a range inclusive into a range exclusive.
///
/// Clamps the end value to u32::MAX if it is u32::MAX.
fn from(val: std::ops::RangeInclusive<u32>) -> Self {
let start_inclusive = *val.start();
let end_exclusive = if *val.end() < u32::MAX {
*val.end() + 1
} else {
*val.end()
};
RankRange {
start_inclusive,
end_exclusive,
}
}
}

impl From<RankRange> for momento_protos::leaderboard::RankRange {
fn from(val: RankRange) -> Self {
momento_protos::leaderboard::RankRange {
Expand Down

0 comments on commit d749551

Please sign in to comment.