Skip to content

Commit e591865

Browse files
authored
Avoid ValueAfterTable when serializing configs (#101)
1 parent 48cff1f commit e591865

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/config.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ impl Default for General {
146146
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
147147
pub struct Pool {
148148
pub pool_mode: String,
149-
pub shards: HashMap<String, Shard>,
150-
pub users: HashMap<String, User>,
151149
pub default_role: String,
152150
pub query_parser_enabled: bool,
153151
pub primary_reads_enabled: bool,
154152
pub sharding_function: String,
153+
pub shards: HashMap<String, Shard>,
154+
pub users: HashMap<String, User>,
155155
}
156156
impl Default for Pool {
157157
fn default() -> Pool {
@@ -190,6 +190,17 @@ fn default_path() -> String {
190190
/// Configuration wrapper.
191191
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
192192
pub struct Config {
193+
// Serializer maintains the order of fields in the struct
194+
// so we should always put simple fields before nested fields
195+
// in all serializable structs to avoid ValueAfterTable errors
196+
// These errors occur when the toml serializer is about to produce
197+
// ambigous toml structure like the one below
198+
// [main]
199+
// field1_under_main = 1
200+
// field2_under_main = 2
201+
// [main.subconf]
202+
// field1_under_subconf = 1
203+
// field3_under_main = 3 # This field will be interpreted as being under subconf and not under main
193204
#[serde(default = "default_path")]
194205
pub path: String,
195206

0 commit comments

Comments
 (0)