Created
August 22, 2016 23:06
-
-
Save causal-agent/a0986b1af2354d98384b97b610eb6b2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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