Skip to content

Commit 5ea258f

Browse files
committed
Sort values in fields applications and classes in the inventory
We sort the `Vec<String>` values which hold the list of nodes which include a certain application or class (the values of the inventory fields `classes` and `applications`) to ensure that the Inventory rendering is deterministic regardless of iteration order over the nodes that are getting rendered.
1 parent 5b8fb6c commit 5ea258f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/inventory.rs

+15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ impl Inventory {
4848
.and_modify(|nodes: &mut Vec<String>| nodes.push(name.clone()))
4949
.or_insert(vec![name.clone()]);
5050
}
51+
// Ensure application and classes values are sorted. We need to consume the iterator,
52+
// but we don't care about the vec of unit types which results from calling sort on the
53+
// values_mut() elements, so we directly drop the resulting Vec.
54+
drop(
55+
inv.classes
56+
.values_mut()
57+
.map(|v| v.sort())
58+
.collect::<Vec<()>>(),
59+
);
60+
drop(
61+
inv.applications
62+
.values_mut()
63+
.map(|v| v.sort())
64+
.collect::<Vec<()>>(),
65+
);
5166
inv.nodes.insert(name.clone(), info);
5267
}
5368
Ok(inv)

0 commit comments

Comments
 (0)