@@ -229,7 +229,11 @@ impl<V: Ord> Ranges<V> {
229
229
}
230
230
231
231
/// Returns true if self contains the specified value.
232
- pub fn contains ( & self , version : & V ) -> bool {
232
+ pub fn contains < Q > ( & self , version : & Q ) -> bool
233
+ where
234
+ V : Borrow < Q > ,
235
+ Q : ?Sized + PartialOrd ,
236
+ {
233
237
self . segments
234
238
. binary_search_by ( |segment| {
235
239
// We have to reverse because we need the segment wrt to the version, while
@@ -470,19 +474,23 @@ impl<V: Ord> Ord for Ranges<V> {
470
474
/// ^ ^ ^
471
475
/// less equal greater
472
476
/// ```
473
- fn within_bounds < V : PartialOrd > ( version : & V , segment : & Interval < V > ) -> Ordering {
477
+ fn within_bounds < Q , V > ( version : & Q , segment : & Interval < V > ) -> Ordering
478
+ where
479
+ V : Borrow < Q > ,
480
+ Q : ?Sized + PartialOrd ,
481
+ {
474
482
let below_lower_bound = match segment {
475
- ( Excluded ( start) , _) => version <= start,
476
- ( Included ( start) , _) => version < start,
483
+ ( Excluded ( start) , _) => version <= start. borrow ( ) ,
484
+ ( Included ( start) , _) => version < start. borrow ( ) ,
477
485
( Unbounded , _) => false ,
478
486
} ;
479
487
if below_lower_bound {
480
488
return Ordering :: Less ;
481
489
}
482
490
let below_upper_bound = match segment {
483
491
( _, Unbounded ) => true ,
484
- ( _, Included ( end) ) => version <= end,
485
- ( _, Excluded ( end) ) => version < end,
492
+ ( _, Included ( end) ) => version <= end. borrow ( ) ,
493
+ ( _, Excluded ( end) ) => version < end. borrow ( ) ,
486
494
} ;
487
495
if below_upper_bound {
488
496
return Ordering :: Equal ;
@@ -1304,7 +1312,7 @@ pub mod tests {
1304
1312
1305
1313
#[ test]
1306
1314
fn always_contains_exact( version in version_strat( ) ) {
1307
- assert!( Ranges :: singleton( version) . contains( & version) ) ;
1315
+ assert!( Ranges :: < u32 > :: singleton( version) . contains( & version) ) ;
1308
1316
}
1309
1317
1310
1318
#[ test]
@@ -1326,7 +1334,7 @@ pub mod tests {
1326
1334
1327
1335
#[ test]
1328
1336
fn from_range_bounds( range in any:: <( Bound <u32 >, Bound <u32 >) >( ) , version in version_strat( ) ) {
1329
- let rv: Ranges <_> = Ranges :: from_range_bounds( range) ;
1337
+ let rv: Ranges <_> = Ranges :: < u32 > :: from_range_bounds( range) ;
1330
1338
assert_eq!( range. contains( & version) , rv. contains( & version) ) ;
1331
1339
}
1332
1340
0 commit comments