@@ -6,6 +6,7 @@ use std::str::FromStr;
6
6
use anyhow:: { Context , Result } ;
7
7
8
8
use crate :: cli:: self_update:: SelfUpdateMode ;
9
+ use crate :: dist:: dist:: Profile ;
9
10
use crate :: errors:: * ;
10
11
use crate :: notifications:: * ;
11
12
use crate :: toml_utils:: * ;
@@ -76,7 +77,7 @@ pub struct Settings {
76
77
pub version : String ,
77
78
pub default_host_triple : Option < String > ,
78
79
pub default_toolchain : Option < String > ,
79
- pub profile : Option < String > ,
80
+ pub profile : Option < Profile > ,
80
81
pub overrides : BTreeMap < String , String > ,
81
82
pub pgp_keys : Option < String > ,
82
83
pub auto_self_update : Option < SelfUpdateMode > ,
@@ -88,7 +89,7 @@ impl Default for Settings {
88
89
version : DEFAULT_METADATA_VERSION . to_owned ( ) ,
89
90
default_host_triple : None ,
90
91
default_toolchain : None ,
91
- profile : Some ( "default" . to_owned ( ) ) ,
92
+ profile : Some ( Profile :: Default ) ,
92
93
overrides : BTreeMap :: new ( ) ,
93
94
pgp_keys : None ,
94
95
auto_self_update : None ,
@@ -150,18 +151,15 @@ impl Settings {
150
151
if !SUPPORTED_METADATA_VERSIONS . contains ( & & * version) {
151
152
return Err ( RustupError :: UnknownMetadataVersion ( version) . into ( ) ) ;
152
153
}
153
- let auto_self_update = match get_opt_string ( & mut table, "auto_self_update" , path) ? {
154
- Some ( auto_self_update) => match SelfUpdateMode :: from_str ( auto_self_update. as_str ( ) ) {
155
- Ok ( mode) => Some ( mode) ,
156
- Err ( _) => None ,
157
- } ,
158
- None => None ,
159
- } ;
154
+ let auto_self_update = get_opt_string ( & mut table, "auto_self_update" , path) ?
155
+ . and_then ( |mode| SelfUpdateMode :: from_str ( mode. as_str ( ) ) . ok ( ) ) ;
156
+ let profile = get_opt_string ( & mut table, "profile" , path) ?
157
+ . and_then ( |p| Profile :: from_str ( p. as_str ( ) ) . ok ( ) ) ;
160
158
Ok ( Self {
161
159
version,
162
160
default_host_triple : get_opt_string ( & mut table, "default_host_triple" , path) ?,
163
161
default_toolchain : get_opt_string ( & mut table, "default_toolchain" , path) ?,
164
- profile : get_opt_string ( & mut table , "profile" , path ) ? ,
162
+ profile,
165
163
overrides : Self :: table_to_overrides ( & mut table, path) ?,
166
164
pgp_keys : get_opt_string ( & mut table, "pgp_keys" , path) ?,
167
165
auto_self_update,
@@ -181,7 +179,7 @@ impl Settings {
181
179
}
182
180
183
181
if let Some ( v) = self . profile {
184
- result. insert ( "profile" . to_owned ( ) , toml:: Value :: String ( v) ) ;
182
+ result. insert ( "profile" . to_owned ( ) , toml:: Value :: String ( v. to_string ( ) ) ) ;
185
183
}
186
184
187
185
if let Some ( v) = self . pgp_keys {
0 commit comments