Skip to content

Commit 1ee4ba8

Browse files
committed
Revert changes to json.rs to match upstream
1 parent fd1e46f commit 1ee4ba8

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

src/json.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
util::*, ConfigurationBuilder, ConfigurationPath, ConfigurationProvider, ConfigurationSource, FileSource,
3-
LoadError, LoadResult, Value,
2+
util::*, ConfigurationBuilder, ConfigurationPath, ConfigurationProvider, ConfigurationSource,
3+
FileSource, LoadError, LoadResult, Value,
44
};
55
use serde_json::{map::Map, Value as JsonValue};
66
use std::collections::HashMap;
@@ -55,7 +55,8 @@ impl JsonVisitor {
5555

5656
fn add_value<T: ToString>(&mut self, value: T) {
5757
let key = self.paths.last().unwrap().to_string();
58-
self.data.insert(key.to_uppercase(), (key, value.to_string().into()));
58+
self.data
59+
.insert(key.to_uppercase(), (key, value.to_string().into()));
5960
}
6061

6162
fn enter_context(&mut self, context: String) {
@@ -135,14 +136,21 @@ impl InnerProvider {
135136
});
136137
}
137138

138-
let previous = std::mem::replace(&mut *self.token.write().unwrap(), SharedChangeToken::default());
139+
let previous = std::mem::replace(
140+
&mut *self.token.write().unwrap(),
141+
SharedChangeToken::default(),
142+
);
139143

140144
previous.notify();
141145
Ok(())
142146
}
143147

144148
fn get(&self, key: &str) -> Option<Value> {
145-
self.data.read().unwrap().get(&key.to_uppercase()).map(|t| t.1.clone())
149+
self.data
150+
.read()
151+
.unwrap()
152+
.get(&key.to_uppercase())
153+
.map(|t| t.1.clone())
146154
}
147155

148156
fn reload_token(&self) -> Box<dyn ChangeToken> {
@@ -178,7 +186,7 @@ impl JsonConfigurationProvider {
178186
std::thread::sleep(provider.file.reload_delay);
179187
provider.load(true).ok();
180188
},
181-
Some(inner.clone()),
189+
Some(inner.clone())
182190
)))
183191
} else {
184192
None

test/json.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ fn add_json_file_should_load_settings_from_file() {
2121

2222
file.write_all(json.to_string().as_bytes()).unwrap();
2323

24-
let config = DefaultConfigurationBuilder::new().add_json_file(&path).build().unwrap();
24+
let config = DefaultConfigurationBuilder::new()
25+
.add_json_file(&path)
26+
.build()
27+
.unwrap();
2528
let section = config.section("Feature").section("NativeCopy");
2629

2730
// act
@@ -41,7 +44,9 @@ fn add_json_file_should_fail_if_file_does_not_exist() {
4144
let path = PathBuf::from(r"C:\fake\settings.json");
4245

4346
// act
44-
let result = DefaultConfigurationBuilder::new().add_json_file(&path).build();
47+
let result = DefaultConfigurationBuilder::new()
48+
.add_json_file(&path)
49+
.build();
4550

4651
// assert
4752
if let Err(error) = result {
@@ -113,7 +118,10 @@ fn simple_json_array_should_be_converted_to_key_value_pairs() {
113118
file.write_all(json.to_string().as_bytes()).unwrap();
114119

115120
// act
116-
let config = DefaultConfigurationBuilder::new().add_json_file(&path).build().unwrap();
121+
let config = DefaultConfigurationBuilder::new()
122+
.add_json_file(&path)
123+
.build()
124+
.unwrap();
117125

118126
// assert
119127
if path.exists() {
@@ -137,7 +145,10 @@ fn complex_json_array_should_be_converted_to_key_value_pairs() {
137145
file.write_all(json.to_string().as_bytes()).unwrap();
138146

139147
// act
140-
let config = DefaultConfigurationBuilder::new().add_json_file(&path).build().unwrap();
148+
let config = DefaultConfigurationBuilder::new()
149+
.add_json_file(&path)
150+
.build()
151+
.unwrap();
141152

142153
// assert
143154
if path.exists() {
@@ -162,7 +173,10 @@ fn nested_json_array_should_be_converted_to_key_value_pairs() {
162173
file.write_all(json.to_string().as_bytes()).unwrap();
163174

164175
// act
165-
let config = DefaultConfigurationBuilder::new().add_json_file(&path).build().unwrap();
176+
let config = DefaultConfigurationBuilder::new()
177+
.add_json_file(&path)
178+
.build()
179+
.unwrap();
166180

167181
// assert
168182
if path.exists() {
@@ -335,7 +349,10 @@ fn json_file_should_reload_when_changed() {
335349
let mut reloaded = mutex.lock().unwrap();
336350

337351
while !*reloaded {
338-
reloaded = event.wait_timeout(reloaded, Duration::from_secs(1)).unwrap().0;
352+
reloaded = event
353+
.wait_timeout(reloaded, Duration::from_secs(1))
354+
.unwrap()
355+
.0;
339356
}
340357

341358
// act

0 commit comments

Comments
 (0)