@@ -9,7 +9,6 @@ use crate::data_dir;
99
1010/// The application config.
1111#[ derive( Serialize , Deserialize ) ]
12- #[ serde( rename_all = "lowercase" ) ]
1312pub ( crate ) struct Config {
1413 /// The selected database backend.
1514 ///
@@ -36,14 +35,14 @@ impl Config {
3635 match fs:: read_to_string ( path) {
3736 Ok ( s) => {
3837 info ! ( "Loading config from {path}" ) ;
39- let c: Self = toml :: from_str ( & s) ?;
38+ let c: Self = serde_json :: from_str ( & s) ?;
4039 c. validate ( ) ?;
4140 Ok ( c)
4241 }
4342 Err ( e) if e. kind ( ) == io:: ErrorKind :: NotFound => {
4443 info ! ( "Config not found at {path}. Initializing default config" ) ;
4544 let c = Config :: standard ( ) ;
46- fs:: write ( path, toml :: to_string ( & c) ?) . map_err ( |e| ConfigError :: Io ( e, path. into ( ) ) ) ?;
45+ fs:: write ( path, serde_json :: to_string ( & c) ?) . map_err ( |e| ConfigError :: Io ( e, path. into ( ) ) ) ?;
4746 Ok ( c)
4847 }
4948 Err ( e) => Err ( ConfigError :: Io ( e, path. into ( ) ) ) ,
@@ -108,17 +107,15 @@ pub(crate) struct PgConfig {
108107#[ derive( Debug ) ]
109108pub enum ConfigError {
110109 Io ( io:: Error , Utf8PathBuf ) ,
111- TomlDe ( toml:: de:: Error ) ,
112- TomlSer ( toml:: ser:: Error ) ,
110+ Json ( serde_json:: Error ) ,
113111 MissingSection ( DbBackend ) ,
114112}
115113
116114impl error:: Error for ConfigError {
117115 fn source ( & self ) -> Option < & ( dyn error:: Error + ' static ) > {
118116 match self {
119117 Self :: Io ( e, _) => Some ( e) ,
120- Self :: TomlDe ( e) => Some ( e) ,
121- Self :: TomlSer ( e) => Some ( e) ,
118+ Self :: Json ( e) => Some ( e) ,
122119 Self :: MissingSection ( _) => None ,
123120 }
124121 }
@@ -128,20 +125,14 @@ impl fmt::Display for ConfigError {
128125 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
129126 match self {
130127 Self :: Io ( e, path) => write ! ( f, "IO error while loading config at {path}: {e}" ) ,
131- Self :: TomlDe ( e) => e. fmt ( f) ,
132- Self :: TomlSer ( e) => e. fmt ( f) ,
128+ Self :: Json ( e) => e. fmt ( f) ,
133129 Self :: MissingSection ( s) => write ! ( f, "{s} config section is missing" ) ,
134130 }
135131 }
136132}
137133
138- impl From < toml:: de:: Error > for ConfigError {
139- fn from ( e : toml:: de:: Error ) -> Self {
140- Self :: TomlDe ( e)
141- }
142- }
143- impl From < toml:: ser:: Error > for ConfigError {
144- fn from ( e : toml:: ser:: Error ) -> Self {
145- Self :: TomlSer ( e)
134+ impl From < serde_json:: Error > for ConfigError {
135+ fn from ( e : serde_json:: Error ) -> Self {
136+ Self :: Json ( e)
146137 }
147138}
0 commit comments