@@ -271,7 +271,7 @@ fn parse_precision(text: &str) -> Result<(Option<usize>, &str), &'static str> {
271
271
}
272
272
273
273
impl FormatSpec {
274
- pub fn parse ( text : & str ) -> Result < Self , & ' static str > {
274
+ pub fn parse ( text : & str ) -> Result < Self , String > {
275
275
// get_integer in CPython
276
276
let ( preconversor, text) = FormatPreconversor :: parse ( text) ;
277
277
let ( mut fill, mut align, text) = parse_fill_and_align ( text) ;
@@ -283,7 +283,7 @@ impl FormatSpec {
283
283
let ( precision, text) = parse_precision ( text) ?;
284
284
let ( format_type, text) = FormatType :: parse ( text) ;
285
285
if !text. is_empty ( ) {
286
- return Err ( "Invalid format specifier" ) ;
286
+ return Err ( "Invalid format specifier" . to_owned ( ) ) ;
287
287
}
288
288
289
289
if zero && fill. is_none ( ) {
@@ -685,7 +685,7 @@ pub enum FormatParseError {
685
685
}
686
686
687
687
impl FromStr for FormatSpec {
688
- type Err = & ' static str ;
688
+ type Err = String ;
689
689
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
690
690
FormatSpec :: parse ( s)
691
691
}
@@ -1104,13 +1104,34 @@ mod tests {
1104
1104
1105
1105
#[ test]
1106
1106
fn test_format_invalid_specification ( ) {
1107
- assert_eq ! ( FormatSpec :: parse( "%3" ) , Err ( "Invalid format specifier" ) ) ;
1108
- assert_eq ! ( FormatSpec :: parse( ".2fa" ) , Err ( "Invalid format specifier" ) ) ;
1109
- assert_eq ! ( FormatSpec :: parse( "ds" ) , Err ( "Invalid format specifier" ) ) ;
1110
- assert_eq ! ( FormatSpec :: parse( "x+" ) , Err ( "Invalid format specifier" ) ) ;
1111
- assert_eq ! ( FormatSpec :: parse( "b4" ) , Err ( "Invalid format specifier" ) ) ;
1112
- assert_eq ! ( FormatSpec :: parse( "o!" ) , Err ( "Invalid format specifier" ) ) ;
1113
- assert_eq ! ( FormatSpec :: parse( "d " ) , Err ( "Invalid format specifier" ) ) ;
1107
+ assert_eq ! (
1108
+ FormatSpec :: parse( "%3" ) ,
1109
+ Err ( "Invalid format specifier" . to_owned( ) )
1110
+ ) ;
1111
+ assert_eq ! (
1112
+ FormatSpec :: parse( ".2fa" ) ,
1113
+ Err ( "Invalid format specifier" . to_owned( ) )
1114
+ ) ;
1115
+ assert_eq ! (
1116
+ FormatSpec :: parse( "ds" ) ,
1117
+ Err ( "Invalid format specifier" . to_owned( ) )
1118
+ ) ;
1119
+ assert_eq ! (
1120
+ FormatSpec :: parse( "x+" ) ,
1121
+ Err ( "Invalid format specifier" . to_owned( ) )
1122
+ ) ;
1123
+ assert_eq ! (
1124
+ FormatSpec :: parse( "b4" ) ,
1125
+ Err ( "Invalid format specifier" . to_owned( ) )
1126
+ ) ;
1127
+ assert_eq ! (
1128
+ FormatSpec :: parse( "o!" ) ,
1129
+ Err ( "Invalid format specifier" . to_owned( ) )
1130
+ ) ;
1131
+ assert_eq ! (
1132
+ FormatSpec :: parse( "d " ) ,
1133
+ Err ( "Invalid format specifier" . to_owned( ) )
1134
+ ) ;
1114
1135
}
1115
1136
1116
1137
#[ test]
0 commit comments