@@ -566,10 +566,8 @@ impl ser::Serialize for ArtifactKind {
566566 S : ser:: Serializer ,
567567 {
568568 let out: Cow < ' _ , str > = match * self {
569- ArtifactKind :: AllBinaries => "bin" . into ( ) ,
570- ArtifactKind :: Staticlib => "staticlib" . into ( ) ,
571- ArtifactKind :: Cdylib => "cdylib" . into ( ) ,
572569 ArtifactKind :: SelectedBinary ( name) => format ! ( "bin:{}" , name. as_str( ) ) . into ( ) ,
570+ _ => self . crate_type ( ) . into ( ) ,
573571 } ;
574572 out. serialize ( s)
575573 }
@@ -578,15 +576,24 @@ impl ser::Serialize for ArtifactKind {
578576impl fmt:: Display for ArtifactKind {
579577 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
580578 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 ( ) ,
585581 } )
586582 }
587583}
588584
589585impl 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+
590597 fn parse ( kind : & str ) -> CargoResult < Self > {
591598 Ok ( match kind {
592599 "bin" => ArtifactKind :: AllBinaries ,
0 commit comments