Skip to content

Commit 81bcf51

Browse files
committed
clippy!: fix large enum variants
..by `Box`ing the descriptor in `LoadMismatch` enum, and by boxing the ChangeSet in `DataAlreadyExists` variant of `CreateWithPersistError`. We allow the large_enum_variant lint for `FileStoreError` for now, as it is planned to be fixed in a future version of `bdk_file_store`.
1 parent b0c1b72 commit 81bcf51

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

clippy.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
# TODO fix, see: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
2-
enum-variant-size-threshold = 1032
3-
# TODO fix, see: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
4-
large-error-threshold = 993
1+
msrv = "1.85.0"

src/wallet/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ pub enum LoadMismatch {
227227
/// Keychain identifying the descriptor.
228228
keychain: KeychainKind,
229229
/// The loaded descriptor.
230-
loaded: Option<ExtendedDescriptor>,
230+
loaded: Option<Box<ExtendedDescriptor>>,
231231
/// The expected descriptor.
232-
expected: Option<ExtendedDescriptor>,
232+
expected: Option<Box<ExtendedDescriptor>>,
233233
},
234234
}
235235

@@ -599,8 +599,8 @@ impl Wallet {
599599
if descriptor.descriptor_id() != exp_desc.descriptor_id() {
600600
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
601601
keychain: KeychainKind::External,
602-
loaded: Some(descriptor),
603-
expected: Some(exp_desc),
602+
loaded: Some(Box::new(descriptor)),
603+
expected: Some(Box::new(exp_desc)),
604604
}));
605605
}
606606
if params.extract_keys {
@@ -609,7 +609,7 @@ impl Wallet {
609609
} else {
610610
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
611611
keychain: KeychainKind::External,
612-
loaded: Some(descriptor),
612+
loaded: Some(Box::new(descriptor)),
613613
expected: None,
614614
}));
615615
}
@@ -630,7 +630,7 @@ impl Wallet {
630630
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
631631
keychain: KeychainKind::Internal,
632632
loaded: None,
633-
expected: Some(exp_desc),
633+
expected: Some(Box::new(exp_desc)),
634634
}));
635635
}
636636
}
@@ -644,7 +644,7 @@ impl Wallet {
644644
None => {
645645
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
646646
keychain: KeychainKind::Internal,
647-
loaded: Some(desc),
647+
loaded: Some(Box::new(desc)),
648648
expected: None,
649649
}))
650650
}
@@ -656,8 +656,8 @@ impl Wallet {
656656
if desc.descriptor_id() != exp_desc.descriptor_id() {
657657
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
658658
keychain: KeychainKind::Internal,
659-
loaded: Some(desc),
660-
expected: Some(exp_desc),
659+
loaded: Some(Box::new(desc)),
660+
expected: Some(Box::new(exp_desc)),
661661
}));
662662
}
663663
if params.extract_keys {

src/wallet/persisted.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ impl<P: WalletPersister> PersistedWallet<P> {
150150
) -> Result<Self, CreateWithPersistError<P::Error>> {
151151
let existing = P::initialize(persister).map_err(CreateWithPersistError::Persist)?;
152152
if !existing.is_empty() {
153-
return Err(CreateWithPersistError::DataAlreadyExists(existing));
153+
return Err(CreateWithPersistError::DataAlreadyExists(Box::new(
154+
existing,
155+
)));
154156
}
155157
let mut inner =
156158
Wallet::create_with_params(params).map_err(CreateWithPersistError::Descriptor)?;
@@ -207,7 +209,9 @@ impl<P: AsyncWalletPersister> PersistedWallet<P> {
207209
.await
208210
.map_err(CreateWithPersistError::Persist)?;
209211
if !existing.is_empty() {
210-
return Err(CreateWithPersistError::DataAlreadyExists(existing));
212+
return Err(CreateWithPersistError::DataAlreadyExists(Box::new(
213+
existing,
214+
)));
211215
}
212216
let mut inner =
213217
Wallet::create_with_params(params).map_err(CreateWithPersistError::Descriptor)?;
@@ -293,6 +297,7 @@ impl WalletPersister for bdk_chain::rusqlite::Connection {
293297
/// Error for [`bdk_file_store`]'s implementation of [`WalletPersister`].
294298
#[cfg(feature = "file_store")]
295299
#[derive(Debug)]
300+
#[allow(clippy::large_enum_variant)]
296301
pub enum FileStoreError {
297302
/// Error when loading from the store.
298303
Load(bdk_file_store::StoreErrorWithDump<ChangeSet>),
@@ -357,7 +362,7 @@ pub enum CreateWithPersistError<E> {
357362
/// Error from persistence.
358363
Persist(E),
359364
/// Persister already has wallet data.
360-
DataAlreadyExists(ChangeSet),
365+
DataAlreadyExists(Box<ChangeSet>),
361366
/// Occurs when the loaded changeset cannot construct [`Wallet`].
362367
Descriptor(DescriptorError),
363368
}

tests/persisted_wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ fn single_descriptor_wallet_persist_and_recover() {
420420
assert_matches!(
421421
err,
422422
Err(LoadWithPersistError::InvalidChangeSet(LoadError::Mismatch(LoadMismatch::Descriptor { keychain, loaded, expected })))
423-
if keychain == KeychainKind::Internal && loaded.is_none() && expected == Some(exp_desc),
423+
if keychain == KeychainKind::Internal && loaded.is_none() && expected == Some(Box::new(exp_desc)),
424424
"single descriptor wallet should refuse change descriptor param"
425425
);
426426
}

0 commit comments

Comments
 (0)