From ba827283be5783ed97e7f97de7e3070ac79a4dd4 Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 2 Sep 2025 19:00:40 +0000 Subject: [PATCH] docs(STYLE.md): prefer BTreeMap and BTreeSet over hash variants --- STYLE.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/STYLE.md b/STYLE.md index 08a01f792..c67f77102 100644 --- a/STYLE.md +++ b/STYLE.md @@ -112,6 +112,18 @@ Follow for `.expect` message style. +## BTreeMap vs HashMap + +Prefer [BTreeMap](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html) +over [HashMap](https://doc.rust-lang.org/std/collections/struct.HashMap.html) +and [BTreeSet](https://doc.rust-lang.org/std/collections/struct.BTreeSet.html) +over [HashSet](https://doc.rust-lang.org/std/collections/struct.HashSet.html) +as iterating over these structures returns items in deterministic order. + +Non-deterministic code may result in difficult to reproduce bugs, +flaky tests, regression tests that miss bugs +or different behavior on different devices when processing the same messages. + ## Logging For logging, use `info!`, `warn!` and `error!` macros.