Skip to content

Commit

Permalink
Add non_exhaustive compiler directive
Browse files Browse the repository at this point in the history
Currently adding variants to enums is a breaking change. In an effort to
reduce the upgrade burden on users we can use the `non_exhaustive`
compiler directive so that adding a new variant does not cause
downstream code to break.

This is, however, a breaking change because downstream users will have
to add a wildcard match arm to any pattern matching code they have for
these enums.

Add `non_exhaustive` to the following tyes:

- `AddressType`
- `Payload`
- `LeafVersion`
  • Loading branch information
tcharding committed May 26, 2022
1 parent 324fa0f commit ecca766
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/util/address.rs
Expand Up @@ -139,6 +139,7 @@ impl From<bech32::Error> for Error {

/// The different types of addresses.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum AddressType {
/// Pay to pubkey hash.
P2pkh,
Expand Down Expand Up @@ -358,6 +359,7 @@ impl From<WitnessVersion> for opcodes::All {

/// The method used to produce an address.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum Payload {
/// P2PKH address.
PubkeyHash(PubkeyHash),
Expand Down
1 change: 1 addition & 0 deletions src/util/taproot.rs
Expand Up @@ -870,6 +870,7 @@ impl fmt::UpperHex for FutureLeafVersion {

/// The leaf version for tapleafs.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum LeafVersion {
/// BIP-342 tapscript.
TapScript,
Expand Down

0 comments on commit ecca766

Please sign in to comment.