From cb42c74f58b65057f2637413c27bd84bfc16173c Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 21 Nov 2023 13:39:25 +1100 Subject: [PATCH] policy: Add section on standard set of derives We can have a standard set of derives to make it easier for new devs to work out what to use and also to help us move towards a uniform set in preparation for crate stabilization. Mention the new `ordered` crate. --- CONTRIBUTING.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 14cb8806..7bd8eb3e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -335,6 +335,27 @@ sure, feel free to ask. If we determine panicking is more practical it must be d panics that could theoretically occur because of bugs in our code must not be documented. +#### Derives + +We try to use standard set of derives if it makes sense: + +``` +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +enum Foo { + Bar, + Baz, +} +``` + +For types that do should not form a total or partial order, or that technically do but it does not +make sense to compare them, we use the `Ordered` trait from the +[`ordered`](https://crates.io/crates/ordered) crate. See `absolute::LockTime` for an example. + +For error types you likely want to use `#[derive(Debug, Clone, PartialEq, Eq)]`. + +See [Errors](#errors) section. + + #### Attributes - `#[track_caller]`: Used on functions that panic on invalid arguments