@@ -20,25 +20,20 @@ pub fn parse(
2020 uri : Option < & String > ,
2121 text : & str ,
2222) -> Result < HashMap < String , Value > , Box < dyn Error + Send + Sync > > {
23- let root = json5_rs:: from_str :: < Val > ( & text) ?;
24- if let Some ( err) = match root {
25- Val :: String ( ref value) => Some ( Unexpected :: Str ( value. clone ( ) ) ) ,
26- Val :: Integer ( value) => Some ( Unexpected :: Integer ( value) ) ,
27- Val :: Float ( value) => Some ( Unexpected :: Float ( value) ) ,
28- Val :: Boolean ( value) => Some ( Unexpected :: Bool ( value) ) ,
29- Val :: Object ( _) => None ,
30- Val :: Array ( _) => Some ( Unexpected :: Seq ) ,
31- Val :: Null => Some ( Unexpected :: Unit ) ,
32- } {
33- return Err ( ConfigError :: invalid_root ( uri, err) ) ;
34- }
35-
36- let value = from_json5_value ( uri, root) ;
37- match value. kind {
38- ValueKind :: Table ( map) => Ok ( map) ,
39-
40- _ => Ok ( HashMap :: new ( ) ) ,
23+ match json5_rs:: from_str :: < Val > ( & text) ? {
24+ Val :: String ( ref value) => Err ( Unexpected :: Str ( value. clone ( ) ) ) ,
25+ Val :: Integer ( value) => Err ( Unexpected :: Integer ( value) ) ,
26+ Val :: Float ( value) => Err ( Unexpected :: Float ( value) ) ,
27+ Val :: Boolean ( value) => Err ( Unexpected :: Bool ( value) ) ,
28+ Val :: Array ( _) => Err ( Unexpected :: Seq ) ,
29+ Val :: Null => Err ( Unexpected :: Unit ) ,
30+ Val :: Object ( o) => match from_json5_value ( uri, Val :: Object ( o) ) . kind {
31+ ValueKind :: Table ( map) => Ok ( map) ,
32+ _ => Ok ( HashMap :: new ( ) ) ,
33+ } ,
4134 }
35+ . map_err ( |err| ConfigError :: invalid_root ( uri, err) )
36+ . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send + Sync > )
4237}
4338
4439fn from_json5_value ( uri : Option < & String > , value : Val ) -> Value {
0 commit comments