@@ -41,7 +41,7 @@ use std::collections::btree_map::Iter as BTreeMapIter;
41
41
use std:: collections:: btree_map:: Keys as BTreeMapKeysIter ;
42
42
use std:: collections:: btree_map:: Values as BTreeMapValuesIter ;
43
43
44
- use std:: fmt;
44
+ use std:: { fmt, str } ;
45
45
use std:: hash:: Hasher ;
46
46
use std:: collections:: hash_map:: DefaultHasher ;
47
47
use std:: collections:: HashSet ;
@@ -137,6 +137,28 @@ pub enum Epoch {
137
137
// as well as changing the default Cargo template.
138
138
}
139
139
140
+ pub const ALL_EPOCHS : & [ Epoch ] = & [ Epoch :: Epoch2015 , Epoch :: Epoch2018 ] ;
141
+
142
+ impl ToString for Epoch {
143
+ fn to_string ( & self ) -> String {
144
+ match * self {
145
+ Epoch :: Epoch2015 => "2015" . into ( ) ,
146
+ Epoch :: Epoch2018 => "2018" . into ( ) ,
147
+ }
148
+ }
149
+ }
150
+
151
+ impl str:: FromStr for Epoch {
152
+ type Err = ( ) ;
153
+ fn from_str ( s : & str ) -> Result < Self , ( ) > {
154
+ match s {
155
+ "2015" => Ok ( Epoch :: Epoch2015 ) ,
156
+ "2018" => Ok ( Epoch :: Epoch2018 ) ,
157
+ _ => Err ( ( ) )
158
+ }
159
+ }
160
+ }
161
+
140
162
impl_stable_hash_for ! ( enum self :: OutputType {
141
163
Bitcode ,
142
164
Assembly ,
@@ -1021,11 +1043,17 @@ macro_rules! options {
1021
1043
1022
1044
fn parse_epoch( slot: & mut Epoch , v: Option <& str >) -> bool {
1023
1045
match v {
1024
- Some ( "2015" ) => * slot = Epoch :: Epoch2015 ,
1025
- Some ( "2018" ) => * slot = Epoch :: Epoch2018 ,
1026
- _ => return false ,
1046
+ Some ( s) => {
1047
+ let epoch = s. parse( ) ;
1048
+ if let Ok ( parsed) = epoch {
1049
+ * slot = parsed;
1050
+ true
1051
+ } else {
1052
+ false
1053
+ }
1054
+ }
1055
+ _ => false ,
1027
1056
}
1028
- true
1029
1057
}
1030
1058
}
1031
1059
) }
0 commit comments