Skip to content

Commit eecc16d

Browse files
committed
Remove non_exhaustive from Network
Issue rust-bitcoin#2225 is long and has many valid opposing opinions. The main argument for having non_exhaustive is that it helps future proof the ecosystem at the cost of pain now. The main argument against having non_exhaustive is why have pain now when adding a network is so rare that having pain then is ok. At the end of the thread Andrew posts: > I continue to think we should have an exhaustive enum, with a bunch of > documentation about how to use it properly. I am warming up to the > "don't have an enum, just have rules for defining your own" but I think > this would be needless work for people who just want to grab an > off-the-shelf set of networks or people who want to make their own enum > but want to see an example of how to do it first. In order to make some forward progress lets remove the `non_exhaustive` now and backport this change to 0.32, 0.31, an 0.30. Later we can add, and release in 0.33, whatever forward protection / libapocalyse protection we want to add. This removes the pain now and gives us a path to prevent future pain - that should keep all parties happy.
1 parent e376e90 commit eecc16d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

bitcoin/src/network/constants.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ use crate::prelude::{String, ToOwned};
6161
pub const PROTOCOL_VERSION: u32 = 70001;
6262

6363
/// The cryptocurrency network to act on.
64+
///
65+
/// This is an exhaustive enum, meaning that we cannot add any future networks without defining a
66+
/// new, incompatible version of this type. If you are using this type directly and wish to support the
67+
/// new network, this will be a breaking change to your APIs and likely require changes in your code.
68+
///
69+
/// If you are concerned about forward compatibility, consider using `T: Into<Params>` instead of
70+
/// this type as a parameter to functions in your public API, or directly using the `Params` type.
71+
// For extensive discussion on the usage of `non_exhaustive` please see:
72+
// https://github.com/rust-bitcoin/rust-bitcoin/issues/2225
6473
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
6574
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6675
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
6776
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
68-
#[non_exhaustive]
6977
pub enum Network {
7078
/// Mainnet Bitcoin.
7179
Bitcoin,

0 commit comments

Comments
 (0)