@@ -752,6 +752,20 @@ impl PartialEq for SourceIdInner {
752
752
}
753
753
}
754
754
755
+ impl SourceKind {
756
+ pub fn protocol ( & self ) -> Option < & str > {
757
+ match self {
758
+ SourceKind :: Path => Some ( "path" ) ,
759
+ SourceKind :: Git ( _) => Some ( "git" ) ,
760
+ SourceKind :: Registry => Some ( "registry" ) ,
761
+ // Sparse registry URL already includes the `sparse+` prefix
762
+ SourceKind :: SparseRegistry => None ,
763
+ SourceKind :: LocalRegistry => Some ( "local-registry" ) ,
764
+ SourceKind :: Directory => Some ( "directory" ) ,
765
+ }
766
+ }
767
+ }
768
+
755
769
/// Forwards to `Ord`
756
770
impl PartialOrd for SourceKind {
757
771
fn partial_cmp ( & self , other : & SourceKind ) -> Option < Ordering > {
@@ -848,53 +862,24 @@ pub struct SourceIdAsUrl<'a> {
848
862
849
863
impl < ' a > fmt:: Display for SourceIdAsUrl < ' a > {
850
864
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
851
- match * self . inner {
852
- SourceIdInner {
853
- kind : SourceKind :: Path ,
854
- ref url,
855
- ..
856
- } => write ! ( f, "path+{}" , url) ,
857
- SourceIdInner {
858
- kind : SourceKind :: Git ( ref reference) ,
859
- ref url,
860
- ref precise,
861
- ..
862
- } => {
863
- write ! ( f, "git+{}" , url) ?;
864
- if let Some ( pretty) = reference. pretty_ref ( self . encoded ) {
865
- write ! ( f, "?{}" , pretty) ?;
866
- }
867
- if let Some ( precise) = precise. as_ref ( ) {
868
- write ! ( f, "#{}" , precise) ?;
869
- }
870
- Ok ( ( ) )
871
- }
872
- SourceIdInner {
873
- kind : SourceKind :: Registry ,
874
- ref url,
875
- ..
876
- } => {
877
- write ! ( f, "registry+{url}" )
865
+ if let Some ( protocol) = self . inner . kind . protocol ( ) {
866
+ write ! ( f, "{protocol}+" ) ?;
867
+ }
868
+ write ! ( f, "{}" , self . inner. url) ?;
869
+ if let SourceIdInner {
870
+ kind : SourceKind :: Git ( ref reference) ,
871
+ ref precise,
872
+ ..
873
+ } = * self . inner
874
+ {
875
+ if let Some ( pretty) = reference. pretty_ref ( self . encoded ) {
876
+ write ! ( f, "?{}" , pretty) ?;
878
877
}
879
- SourceIdInner {
880
- kind : SourceKind :: SparseRegistry ,
881
- ref url,
882
- ..
883
- } => {
884
- // Sparse registry URL already includes the `sparse+` prefix
885
- write ! ( f, "{url}" )
878
+ if let Some ( precise) = precise. as_ref ( ) {
879
+ write ! ( f, "#{}" , precise) ?;
886
880
}
887
- SourceIdInner {
888
- kind : SourceKind :: LocalRegistry ,
889
- ref url,
890
- ..
891
- } => write ! ( f, "local-registry+{}" , url) ,
892
- SourceIdInner {
893
- kind : SourceKind :: Directory ,
894
- ref url,
895
- ..
896
- } => write ! ( f, "directory+{}" , url) ,
897
881
}
882
+ Ok ( ( ) )
898
883
}
899
884
}
900
885
0 commit comments