Merge pull request #151 from EPashkin/fix_table_values_sorting
Fixed sorting of table values
This commit is contained in:
commit
c680668d22
|
@ -367,12 +367,12 @@ impl ser::Serialize for Value {
|
||||||
// array-of-tables) as all keys must be emitted first.
|
// array-of-tables) as all keys must be emitted first.
|
||||||
for (k, v) in t {
|
for (k, v) in t {
|
||||||
if !v.is_table() && !v.is_array() ||
|
if !v.is_table() && !v.is_array() ||
|
||||||
(v.as_array().map(|a| a.len() == 0).unwrap_or(false)) {
|
(v.as_array().map(|a| !a.iter().any(|v| v.is_table())).unwrap_or(false)) {
|
||||||
map.serialize_entry(k, v)?;
|
map.serialize_entry(k, v)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (k, v) in t {
|
for (k, v) in t {
|
||||||
if v.as_array().map(|a| a.len() > 0).unwrap_or(false) {
|
if v.as_array().map(|a| a.iter().any(|v| v.is_table())).unwrap_or(false) {
|
||||||
map.serialize_entry(k, v)?;
|
map.serialize_entry(k, v)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,4 +94,10 @@ fn table() {
|
||||||
\n\
|
\n\
|
||||||
[[test2]]\n\
|
[[test2]]\n\
|
||||||
test = [[2, 3], [\"foo\", \"bar\"]]\n");
|
test = [[2, 3], [\"foo\", \"bar\"]]\n");
|
||||||
|
assert_eq!(Table(map! {
|
||||||
|
"test" => Array(vec![Integer(2)]),
|
||||||
|
"test2" => Integer(2)
|
||||||
|
}).to_string(),
|
||||||
|
"test = [2]\n\
|
||||||
|
test2 = 2\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue