13
13
//! Docs: <https://forge.rust-lang.org/infra/channel-layout.html>
14
14
15
15
use std:: collections:: HashMap ;
16
+ use std:: fmt;
16
17
use std:: hash:: { Hash , Hasher } ;
17
18
use std:: str:: FromStr ;
18
19
@@ -25,8 +26,6 @@ use crate::utils::toml_utils::*;
25
26
26
27
use super :: { config:: Config , dist:: ToolchainDesc } ;
27
28
28
- pub ( crate ) const SUPPORTED_MANIFEST_VERSIONS : [ & str ; 1 ] = [ "2" ] ;
29
-
30
29
/// Used by the `installed_components` function
31
30
pub ( crate ) struct ComponentStatus {
32
31
pub component : Component ,
@@ -37,7 +36,7 @@ pub(crate) struct ComponentStatus {
37
36
38
37
#[ derive( Clone , Debug , Eq , PartialEq ) ]
39
38
pub struct Manifest {
40
- manifest_version : String ,
39
+ manifest_version : ManifestVersion ,
41
40
pub date : String ,
42
41
pub packages : HashMap < String , Package > ,
43
42
pub renames : HashMap < String , String > ,
@@ -133,12 +132,11 @@ impl Manifest {
133
132
134
133
pub ( crate ) fn from_toml ( mut table : toml:: value:: Table , path : & str ) -> Result < Self > {
135
134
let version = get_string ( & mut table, "manifest-version" , path) ?;
136
- if !SUPPORTED_MANIFEST_VERSIONS . contains ( & & * version) {
137
- bail ! ( RustupError :: UnsupportedVersion ( version) ) ;
138
- }
135
+ let manifest_version = ManifestVersion :: from_str ( & version) ?;
136
+
139
137
let ( renames, reverse_renames) = Self :: table_to_renames ( & mut table, path) ?;
140
138
Ok ( Self {
141
- manifest_version : version ,
139
+ manifest_version,
142
140
date : get_string ( & mut table, "date" , path) ?,
143
141
packages : Self :: table_to_packages ( & mut table, path) ?,
144
142
renames,
@@ -152,7 +150,7 @@ impl Manifest {
152
150
result. insert ( "date" . to_owned ( ) , toml:: Value :: String ( self . date ) ) ;
153
151
result. insert (
154
152
"manifest-version" . to_owned ( ) ,
155
- toml:: Value :: String ( self . manifest_version ) ,
153
+ toml:: Value :: String ( self . manifest_version . to_string ( ) ) ,
156
154
) ;
157
155
158
156
let renames = Self :: renames_to_table ( self . renames ) ;
@@ -719,6 +717,37 @@ impl Component {
719
717
}
720
718
}
721
719
720
+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
721
+ pub ( crate ) enum ManifestVersion {
722
+ #[ default]
723
+ V2 ,
724
+ }
725
+
726
+ impl ManifestVersion {
727
+ pub fn as_str ( & self ) -> & ' static str {
728
+ match self {
729
+ Self :: V2 => "2" ,
730
+ }
731
+ }
732
+ }
733
+
734
+ impl FromStr for ManifestVersion {
735
+ type Err = RustupError ;
736
+
737
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
738
+ match s {
739
+ "2" => Ok ( Self :: V2 ) ,
740
+ _ => Err ( RustupError :: UnsupportedVersion ( s. to_owned ( ) ) ) ,
741
+ }
742
+ }
743
+ }
744
+
745
+ impl fmt:: Display for ManifestVersion {
746
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
747
+ write ! ( f, "{}" , self . as_str( ) )
748
+ }
749
+ }
750
+
722
751
#[ cfg( test) ]
723
752
mod tests {
724
753
use crate :: dist:: dist:: TargetTriple ;
0 commit comments