Skip to content

Commit eabb1d6

Browse files
committed
feat!: Add #[non_exhaustive] to ChangeSet structs in tx_graph, keychain_txout, local_chain
Add #[non_exhaustive] attribute to the ChangeSet structs to prevent downstream crates from exhaustively matching or constructing instances using struct literal syntax, allowing future additions without breaking compatibility. The change improves forward compatibility by allowing new fields to be added without breaking downstream code in future releases.
1 parent 63923c6 commit eabb1d6

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

crates/chain/src/indexer/keychain_txout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ impl<K: core::fmt::Debug> std::error::Error for InsertDescriptorError<K> {}
10211021
#[derive(Clone, Debug, Default, PartialEq)]
10221022
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
10231023
#[must_use]
1024+
#[non_exhaustive]
10241025
pub struct ChangeSet {
10251026
/// Maps each `DescriptorId` to its last revealed derivation index.
10261027
pub last_revealed: BTreeMap<DescriptorId, u32>,

crates/chain/src/local_chain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ impl LocalChain {
408408
/// The [`ChangeSet`] represents changes to [`LocalChain`].
409409
#[derive(Debug, Default, Clone, PartialEq)]
410410
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
411+
#[non_exhaustive]
411412
pub struct ChangeSet {
412413
/// Changes to the [`LocalChain`] blocks.
413414
///

crates/chain/src/tx_graph.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ impl<A: Anchor> From<TxUpdate<A>> for TxGraph<A> {
173173
///
174174
/// [module-level documentation]: crate::tx_graph
175175
#[derive(Clone, Debug, PartialEq)]
176+
#[non_exhaustive]
176177
pub struct TxGraph<A = ConfirmationBlockTime> {
177178
txs: HashMap<Txid, TxNodeInternal>,
178179
spends: BTreeMap<OutPoint, HashSet<Txid>>,
@@ -1415,6 +1416,7 @@ impl<A: Anchor> TxGraph<A> {
14151416
))
14161417
)]
14171418
#[must_use]
1419+
#[non_exhaustive]
14181420
pub struct ChangeSet<A = ()> {
14191421
/// Added transactions.
14201422
pub txs: BTreeSet<Arc<Transaction>>,

0 commit comments

Comments
 (0)