@@ -2,44 +2,43 @@ use std::error::Error;
22
33use crate :: format;
44use crate :: map:: Map ;
5- use crate :: value:: Value ;
5+ use crate :: value:: { Value , ValueKind } ;
66
77pub fn parse (
88 uri : Option < & String > ,
99 text : & str ,
1010) -> Result < Map < String , Value > , Box < dyn Error + Send + Sync > > {
11- // Parse a TOML value from the provided text
12- let value = from_toml_value ( uri, & toml:: from_str ( text) ?) ;
11+ // Parse a TOML input from the provided text
12+ let value = from_toml_value ( uri, toml:: from_str ( text) ?) ;
1313 format:: extract_root_table ( uri, value)
1414}
1515
16- fn from_toml_value ( uri : Option < & String > , value : & toml:: Value ) -> Value {
17- match * value {
18- toml:: Value :: String ( ref value ) => Value :: new ( uri , value . to_string ( ) ) ,
19- toml:: Value :: Float ( value ) => Value :: new ( uri , value ) ,
20- toml:: Value :: Integer ( value ) => Value :: new ( uri , value ) ,
21- toml:: Value :: Boolean ( value ) => Value :: new ( uri , value ) ,
22-
23- toml :: Value :: Table ( ref table ) => {
24- let mut m = Map :: new ( ) ;
25-
26- for ( key , value ) in table {
27- m . insert ( key . clone ( ) , from_toml_value ( uri, value ) ) ;
28- }
29-
30- Value :: new ( uri , m)
16+ fn from_toml_value ( uri : Option < & String > , value : toml:: Value ) -> Value {
17+ let vk = match value {
18+ toml:: Value :: Datetime ( v ) => ValueKind :: String ( v . to_string ( ) ) ,
19+ toml:: Value :: String ( v ) => ValueKind :: String ( v ) ,
20+ toml:: Value :: Float ( v ) => ValueKind :: Float ( v ) ,
21+ toml:: Value :: Integer ( v ) => ValueKind :: I64 ( v ) ,
22+ toml :: Value :: Boolean ( v ) => ValueKind :: Boolean ( v ) ,
23+
24+ toml :: Value :: Table ( table ) => {
25+ let m = table
26+ . into_iter ( )
27+ . map ( | ( k , v ) | ( k , from_toml_value ( uri, v ) ) )
28+ . collect ( ) ;
29+
30+ ValueKind :: Table ( m)
3131 }
3232
33- toml:: Value :: Array ( ref array) => {
34- let mut l = Vec :: new ( ) ;
35-
36- for value in array {
37- l. push ( from_toml_value ( uri, value) ) ;
38- }
33+ toml:: Value :: Array ( array) => {
34+ let l = array
35+ . into_iter ( )
36+ . map ( |v| from_toml_value ( uri, v) )
37+ . collect ( ) ;
3938
40- Value :: new ( uri , l)
39+ ValueKind :: Array ( l)
4140 }
41+ } ;
4242
43- toml:: Value :: Datetime ( ref datetime) => Value :: new ( uri, datetime. to_string ( ) ) ,
44- }
43+ Value :: new ( uri, vk)
4544}
0 commit comments