@@ -41,7 +41,7 @@ use std::collections::btree_map::Iter as BTreeMapIter;
4141use std:: collections:: btree_map:: Keys as BTreeMapKeysIter ;
4242use std:: collections:: btree_map:: Values as BTreeMapValuesIter ;
4343
44- use std:: fmt;
44+ use std:: { fmt, str } ;
4545use std:: hash:: Hasher ;
4646use std:: collections:: hash_map:: DefaultHasher ;
4747use std:: collections:: HashSet ;
@@ -137,6 +137,28 @@ pub enum Epoch {
137137 // as well as changing the default Cargo template.
138138}
139139
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+
140162impl_stable_hash_for ! ( enum self :: OutputType {
141163 Bitcode ,
142164 Assembly ,
@@ -1021,11 +1043,17 @@ macro_rules! options {
10211043
10221044 fn parse_epoch( slot: & mut Epoch , v: Option <& str >) -> bool {
10231045 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 ,
10271056 }
1028- true
10291057 }
10301058 }
10311059) }
0 commit comments