Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
use std::ops::{Range, RangeFrom, RangeTo};
pub trait RangeExt<T> {
fn before(&self) -> RangeTo<T>;
fn after(&self) -> RangeFrom<T>;
}
impl<T: Copy> RangeExt<T> for Range<T> {
fn before(&self) -> RangeTo<T> {
..self.start
}
fn after(&self) -> RangeFrom<T> {
self.end..
}
}
#[cfg(test)]
mod tests {
use super::RangeExt;
#[test]
fn range_ext() {
assert_eq!(..3, (3..5).before());
assert_eq!(5.., (3..5).after());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment