@@ -97,6 +97,7 @@ mod arithmetic;
97
97
98
98
// From<T>, To<T>, TryFrom<T> impls
99
99
mod impl_convert;
100
+ mod impl_trait_from_str;
100
101
101
102
// Add<T>, Sub<T>, etc...
102
103
mod impl_ops;
@@ -918,15 +919,6 @@ impl From<ParseBigIntError> for ParseBigDecimalError {
918
919
}
919
920
}
920
921
921
- impl FromStr for BigDecimal {
922
- type Err = ParseBigDecimalError ;
923
-
924
- #[ inline]
925
- fn from_str ( s : & str ) -> Result < BigDecimal , ParseBigDecimalError > {
926
- BigDecimal :: from_str_radix ( s, 10 )
927
- }
928
- }
929
-
930
922
#[ allow( deprecated) ] // trim_right_match -> trim_end_match
931
923
impl Hash for BigDecimal {
932
924
fn hash < H : Hasher > ( & self , state : & mut H ) {
@@ -2158,36 +2150,6 @@ mod bigdecimal_tests {
2158
2150
}
2159
2151
}
2160
2152
2161
- #[ test]
2162
- fn test_from_str ( ) {
2163
- let vals = vec ! [
2164
- ( "1331.107" , 1331107 , 3 ) ,
2165
- ( "1.0" , 10 , 1 ) ,
2166
- ( "2e1" , 2 , -1 ) ,
2167
- ( "0.00123" , 123 , 5 ) ,
2168
- ( "-123" , -123 , 0 ) ,
2169
- ( "-1230" , -1230 , 0 ) ,
2170
- ( "12.3" , 123 , 1 ) ,
2171
- ( "123e-1" , 123 , 1 ) ,
2172
- ( "1.23e+1" , 123 , 1 ) ,
2173
- ( "1.23E+3" , 123 , -1 ) ,
2174
- ( "1.23E-8" , 123 , 10 ) ,
2175
- ( "-1.23E-10" , -123 , 12 ) ,
2176
- ( "123_" , 123 , 0 ) ,
2177
- ( "31_862_140.830_686_979" , 31862140830686979 , 9 ) ,
2178
- ( "-1_1.2_2" , -1122 , 2 ) ,
2179
- ( "999.521_939" , 999521939 , 6 ) ,
2180
- ( "679.35_84_03E-2" , 679358403 , 8 ) ,
2181
- ( "271576662.__E4" , 271576662 , -4 ) ,
2182
- ] ;
2183
-
2184
- for & ( source, val, scale) in vals. iter ( ) {
2185
- let x = BigDecimal :: from_str ( source) . unwrap ( ) ;
2186
- assert_eq ! ( x. int_val. to_i64( ) . unwrap( ) , val) ;
2187
- assert_eq ! ( x. scale, scale) ;
2188
- }
2189
- }
2190
-
2191
2153
#[ test]
2192
2154
fn test_fmt ( ) {
2193
2155
let vals = vec ! [
@@ -2266,47 +2228,6 @@ mod bigdecimal_tests {
2266
2228
}
2267
2229
}
2268
2230
2269
- #[ test]
2270
- #[ should_panic( expected = "InvalidDigit" ) ]
2271
- fn test_bad_string_nan ( ) {
2272
- BigDecimal :: from_str ( "hello" ) . unwrap ( ) ;
2273
- }
2274
- #[ test]
2275
- #[ should_panic( expected = "Empty" ) ]
2276
- fn test_bad_string_empty ( ) {
2277
- BigDecimal :: from_str ( "" ) . unwrap ( ) ;
2278
- }
2279
- #[ test]
2280
- #[ should_panic( expected = "InvalidDigit" ) ]
2281
- fn test_bad_string_invalid_char ( ) {
2282
- BigDecimal :: from_str ( "12z3.12" ) . unwrap ( ) ;
2283
- }
2284
- #[ test]
2285
- #[ should_panic( expected = "InvalidDigit" ) ]
2286
- fn test_bad_string_nan_exponent ( ) {
2287
- BigDecimal :: from_str ( "123.123eg" ) . unwrap ( ) ;
2288
- }
2289
- #[ test]
2290
- #[ should_panic( expected = "Empty" ) ]
2291
- fn test_bad_string_empty_exponent ( ) {
2292
- BigDecimal :: from_str ( "123.123E" ) . unwrap ( ) ;
2293
- }
2294
- #[ test]
2295
- #[ should_panic( expected = "InvalidDigit" ) ]
2296
- fn test_bad_string_multiple_decimal_points ( ) {
2297
- BigDecimal :: from_str ( "123.12.45" ) . unwrap ( ) ;
2298
- }
2299
- #[ test]
2300
- #[ should_panic( expected = "Empty" ) ]
2301
- fn test_bad_string_only_decimal ( ) {
2302
- BigDecimal :: from_str ( "." ) . unwrap ( ) ;
2303
- }
2304
- #[ test]
2305
- #[ should_panic( expected = "Empty" ) ]
2306
- fn test_bad_string_only_decimal_and_exponent ( ) {
2307
- BigDecimal :: from_str ( ".e4" ) . unwrap ( ) ;
2308
- }
2309
-
2310
2231
#[ test]
2311
2232
fn test_from_i128 ( ) {
2312
2233
let value = BigDecimal :: from_i128 ( -368934881474191032320 ) . unwrap ( ) ;
0 commit comments