File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4242
4343 ( a + b - one) / b
4444}
45+
46+ pub ( crate ) trait RangeExt < T > {
47+ fn overlaps ( & self , other : Self ) -> bool ;
48+ fn is_superset ( & self , other : Self ) -> bool ;
49+ fn len ( & self ) -> usize ;
50+ fn range ( & self ) -> T ;
51+ }
52+
53+ impl < T : PartialOrd < T > + Default + Copy + Sub < Output = T > > RangeExt < T > for core:: ops:: Range < T >
54+ where
55+ usize : core:: convert:: TryFrom < T > ,
56+ <usize as core:: convert:: TryFrom < T > >:: Error : core:: fmt:: Debug ,
57+ {
58+ fn overlaps ( & self , other : Self ) -> bool {
59+ !( self . is_empty ( ) || other. is_empty ( ) || self . end <= other. start || other. end <= self . start )
60+ }
61+ fn is_superset ( & self , other : Self ) -> bool {
62+ !self . is_empty ( )
63+ && ( other. is_empty ( ) || ( other. start >= self . start && other. end <= self . end ) )
64+ }
65+ fn range ( & self ) -> T {
66+ if self . is_empty ( ) {
67+ Default :: default ( )
68+ } else {
69+ self . end - self . start
70+ }
71+ }
72+ fn len ( & self ) -> usize {
73+ self . range ( ) . try_into ( ) . unwrap ( )
74+ }
75+ }
You can’t perform that action at this time.
0 commit comments