@@ -566,10 +566,8 @@ impl ser::Serialize for ArtifactKind {
566
566
S : ser:: Serializer ,
567
567
{
568
568
let out: Cow < ' _ , str > = match * self {
569
- ArtifactKind :: AllBinaries => "bin" . into ( ) ,
570
- ArtifactKind :: Staticlib => "staticlib" . into ( ) ,
571
- ArtifactKind :: Cdylib => "cdylib" . into ( ) ,
572
569
ArtifactKind :: SelectedBinary ( name) => format ! ( "bin:{}" , name. as_str( ) ) . into ( ) ,
570
+ _ => self . crate_type ( ) . into ( ) ,
573
571
} ;
574
572
out. serialize ( s)
575
573
}
@@ -578,15 +576,24 @@ impl ser::Serialize for ArtifactKind {
578
576
impl fmt:: Display for ArtifactKind {
579
577
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
580
578
f. write_str ( match self {
581
- ArtifactKind :: Cdylib => "cdylib" ,
582
- ArtifactKind :: Staticlib => "staticlib" ,
583
- ArtifactKind :: AllBinaries => "bin" ,
584
- ArtifactKind :: SelectedBinary ( bin_name) => return write ! ( f, "bin:{}" , bin_name) ,
579
+ ArtifactKind :: SelectedBinary ( bin_name) => return write ! ( f, "bin:{bin_name}" ) ,
580
+ _ => self . crate_type ( ) ,
585
581
} )
586
582
}
587
583
}
588
584
589
585
impl ArtifactKind {
586
+ /// Returns a string of crate type of the artifact being built.
587
+ ///
588
+ /// Note that the name of `SelectedBinary` would be dropped and displayed as `bin`.
589
+ pub fn crate_type ( & self ) -> & ' static str {
590
+ match self {
591
+ ArtifactKind :: AllBinaries | ArtifactKind :: SelectedBinary ( _) => "bin" ,
592
+ ArtifactKind :: Cdylib => "cdylib" ,
593
+ ArtifactKind :: Staticlib => "staticlib" ,
594
+ }
595
+ }
596
+
590
597
fn parse ( kind : & str ) -> CargoResult < Self > {
591
598
Ok ( match kind {
592
599
"bin" => ArtifactKind :: AllBinaries ,
0 commit comments