@@ -468,48 +468,30 @@ impl SourceId {
468
468
469
469
/// Creates a new `SourceId` from this source with the given `precise`.
470
470
pub fn with_git_precise ( self , fragment : Option < String > ) -> SourceId {
471
- let precise = fragment. map ( |f| Precise :: GitUrlFragment ( f) ) ;
472
- if self . inner . precise == precise {
473
- self
474
- } else {
475
- SourceId :: wrap ( SourceIdInner {
476
- precise,
477
- ..( * self . inner ) . clone ( )
478
- } )
479
- }
471
+ self . with_precise ( & fragment. map ( |f| Precise :: GitUrlFragment ( f) ) )
480
472
}
481
473
482
474
/// Creates a new `SourceId` from this source without a `precise`.
483
475
pub fn without_precise ( self ) -> SourceId {
484
- if self . inner . precise . is_none ( ) {
485
- self
486
- } else {
487
- SourceId :: wrap ( SourceIdInner {
488
- precise : None ,
489
- ..( * self . inner ) . clone ( )
490
- } )
491
- }
476
+ self . with_precise ( & None )
492
477
}
493
478
494
479
/// Creates a new `SourceId` from this source without a `precise`.
495
480
pub fn with_locked_precise ( self ) -> SourceId {
496
- if self . inner . precise == Some ( Precise :: Locked ) {
497
- self
498
- } else {
499
- SourceId :: wrap ( SourceIdInner {
500
- precise : Some ( Precise :: Locked ) ,
501
- ..( * self . inner ) . clone ( )
502
- } )
503
- }
481
+ self . with_precise ( & Some ( Precise :: Locked ) )
504
482
}
505
483
506
484
/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
507
485
pub fn with_precise_from ( self , v : Self ) -> SourceId {
508
- if self . inner . precise == v. inner . precise {
486
+ self . with_precise ( & v. inner . precise )
487
+ }
488
+
489
+ fn with_precise ( self , precise : & Option < Precise > ) -> SourceId {
490
+ if & self . inner . precise == precise {
509
491
self
510
492
} else {
511
493
SourceId :: wrap ( SourceIdInner {
512
- precise : v . inner . precise . clone ( ) ,
494
+ precise : precise. clone ( ) ,
513
495
..( * self . inner ) . clone ( )
514
496
} )
515
497
}
0 commit comments