Skip to content

Instantly share code, notes, and snippets.

@causal-agent
Created August 22, 2016 23:06
Show Gist options
  • Save causal-agent/a0986b1af2354d98384b97b610eb6b2f to your computer and use it in GitHub Desktop.
Save causal-agent/a0986b1af2354d98384b97b610eb6b2f to your computer and use it in GitHub Desktop.
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