Skip to content

Commit 4ce635d

Browse files
xiekeyangalxiord
authored andcommitted
mmds: try each value item in fn check_data_valid
Improve a little code progress, by converting object into iterator. Signed-off-by: xiekeyang <[email protected]>
1 parent f244f51 commit 4ce635d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/mmds/src/data_store.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ impl Mmds {
5454
/// an UnsupportedValueType error if the data contain any value type other than
5555
/// Strings, arrays and dictionaries.
5656
pub fn check_data_valid(data: &Value) -> Result<(), Error> {
57-
if let Some(map) = data.as_object() {
58-
for key in map.keys() {
59-
Mmds::check_data_valid(&map[key])?;
60-
}
57+
if data.is_string() {
58+
Ok(())
59+
} else if let Some(map) = data.as_object() {
60+
map.values()
61+
.try_for_each(|value| Mmds::check_data_valid(value))
6162
} else if let Some(array) = data.as_array() {
62-
for obj in array {
63-
Mmds::check_data_valid(&obj)?;
64-
}
65-
} else if !data.is_string() {
66-
return Err(Error::UnsupportedValueType);
63+
array
64+
.iter()
65+
.try_for_each(|value| Mmds::check_data_valid(value))
66+
} else {
67+
Err(Error::UnsupportedValueType)
6768
}
68-
Ok(())
6969
}
7070

7171
pub fn put_data(&mut self, data: Value) -> Result<(), Error> {

0 commit comments

Comments
 (0)