@@ -29,8 +29,8 @@ mod serde_impl;
29
29
#[ derive( Debug , Snafu , PartialEq ) ]
30
30
#[ snafu( module) ]
31
31
pub enum DurationParseError {
32
- #[ snafu( display( "invalid input, either empty or contains non-ascii characters " ) ) ]
33
- InvalidInput ,
32
+ #[ snafu( display( "empty input " ) ) ]
33
+ EmptyInput ,
34
34
35
35
#[ snafu( display( "unexpected character {chr:?}" ) ) ]
36
36
UnexpectedCharacter { chr : char } ,
@@ -55,9 +55,8 @@ impl FromStr for Duration {
55
55
use duration_parse_error:: * ;
56
56
let input = s. trim ( ) ;
57
57
58
- // An empty or non-ascii input is invalid
59
- if input. is_empty ( ) || !input. is_ascii ( ) {
60
- return Err ( DurationParseError :: InvalidInput ) ;
58
+ if input. is_empty ( ) {
59
+ return EmptyInputSnafu . fail ( ) ;
61
60
}
62
61
63
62
let mut chars = input. char_indices ( ) . peekable ( ) ;
@@ -247,8 +246,8 @@ mod test {
247
246
#[ rstest]
248
247
#[ case( "1D" , DurationParseError :: ParseUnitError { unit: "D" . into( ) } ) ]
249
248
#[ case( "2d2" , DurationParseError :: NoUnit { value: 2 } ) ]
250
- #[ case( "1ä" , DurationParseError :: InvalidInput ) ]
251
- #[ case( " " , DurationParseError :: InvalidInput ) ]
249
+ #[ case( "1ä" , DurationParseError :: EmptyInput ) ]
250
+ #[ case( " " , DurationParseError :: EmptyInput ) ]
252
251
fn parse_invalid ( #[ case] input : & str , #[ case] expected_err : DurationParseError ) {
253
252
let err = Duration :: from_str ( input) . unwrap_err ( ) ;
254
253
assert_eq ! ( err, expected_err)
0 commit comments