Skip to content

Commit 2459cec

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 2459cec

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 the finite enumeration of the current networks defined by Bitcoin Core v29, nothing less
66+
/// and nothing more. If Bitcoin Core defines a new network your software will likely need to change
67+
/// but in order to make usage of this type ergonomic right now the type is not `non_exhaustive`.
68+
///
69+
/// If you are a library writer, in order to make your APIs more maintainable and more interoperable
70+
/// with the wider ecosystem, consider using [`Params`] and/or [`NetworkKind`] instead of this 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)