File tree 2 files changed +14
-5
lines changed 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 2
2
name = " interval"
3
3
version = " 0.1.0"
4
4
authors = [
" You <[email protected] >" ]
5
+ edition = " 2018"
5
6
6
7
[dependencies ]
Original file line number Diff line number Diff line change
1
+ #![ warn( rust_2018_idioms) ]
2
+ #![ allow( elided_lifetimes_in_paths) ]
3
+
1
4
#[ derive( Debug , PartialEq ) ]
2
5
struct Interval < T > {
3
6
lower : T , // inclusive
4
- upper : T // exclusive
7
+ upper : T , // exclusive
5
8
}
6
9
7
10
use std:: cmp:: { Ordering , PartialOrd } ;
8
11
9
12
impl < T : PartialOrd > PartialOrd < Interval < T > > for Interval < T > {
10
13
fn partial_cmp ( & self , other : & Interval < T > ) -> Option < Ordering > {
11
- if self == other { Some ( Ordering :: Equal ) }
12
- else if self . lower >= other. upper { Some ( Ordering :: Greater ) }
13
- else if self . upper <= other. lower { Some ( Ordering :: Less ) }
14
- else { None }
14
+ if self == other {
15
+ Some ( Ordering :: Equal )
16
+ } else if self . lower >= other. upper {
17
+ Some ( Ordering :: Greater )
18
+ } else if self . upper <= other. lower {
19
+ Some ( Ordering :: Less )
20
+ } else {
21
+ None
22
+ }
15
23
}
16
24
}
17
25
You can’t perform that action at this time.
0 commit comments