Skip to content

Commit 4b625c0

Browse files
committed
clippy!: Box large enum variants
This is a fix to address clippy lints - `clippy::large_enum_variant` - `clippy::result_large_error` BREAKING: The types `LoadMismatch`, `FileStoreError`, and `CreateWithPersistError` are changed as a result of the now boxed variants.
1 parent 0eb4a9c commit 4b625c0

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-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.63.0"

wallet/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

@@ -565,8 +565,8 @@ impl Wallet {
565565
if descriptor.descriptor_id() != exp_desc.descriptor_id() {
566566
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
567567
keychain: KeychainKind::External,
568-
loaded: Some(descriptor),
569-
expected: Some(exp_desc),
568+
loaded: Some(Box::new(descriptor)),
569+
expected: Some(Box::new(exp_desc)),
570570
}));
571571
}
572572
if params.extract_keys {
@@ -575,7 +575,7 @@ impl Wallet {
575575
} else {
576576
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
577577
keychain: KeychainKind::External,
578-
loaded: Some(descriptor),
578+
loaded: Some(Box::new(descriptor)),
579579
expected: None,
580580
}));
581581
}
@@ -595,7 +595,7 @@ impl Wallet {
595595
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
596596
keychain: KeychainKind::Internal,
597597
loaded: None,
598-
expected: Some(exp_desc),
598+
expected: Some(Box::new(exp_desc)),
599599
}));
600600
}
601601
}
@@ -609,7 +609,7 @@ impl Wallet {
609609
None => {
610610
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
611611
keychain: KeychainKind::Internal,
612-
loaded: Some(desc),
612+
loaded: Some(Box::new(desc)),
613613
expected: None,
614614
}))
615615
}
@@ -621,8 +621,8 @@ impl Wallet {
621621
if desc.descriptor_id() != exp_desc.descriptor_id() {
622622
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
623623
keychain: KeychainKind::Internal,
624-
loaded: Some(desc),
625-
expected: Some(exp_desc),
624+
loaded: Some(Box::new(desc)),
625+
expected: Some(Box::new(exp_desc)),
626626
}));
627627
}
628628
if params.extract_keys {

wallet/src/wallet/persisted.rs

Lines changed: 9 additions & 4 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)?;
@@ -295,7 +299,7 @@ impl WalletPersister for bdk_chain::rusqlite::Connection {
295299
#[derive(Debug)]
296300
pub enum FileStoreError {
297301
/// Error when loading from the store.
298-
Load(bdk_file_store::StoreErrorWithDump<ChangeSet>),
302+
Load(Box<bdk_file_store::StoreErrorWithDump<ChangeSet>>),
299303
/// Error when writing to the store.
300304
Write(std::io::Error),
301305
}
@@ -322,6 +326,7 @@ impl WalletPersister for bdk_file_store::Store<ChangeSet> {
322326
persister
323327
.dump()
324328
.map(Option::unwrap_or_default)
329+
.map_err(Box::new)
325330
.map_err(FileStoreError::Load)
326331
}
327332

@@ -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
}

wallet/tests/persisted_wallet.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ fn single_descriptor_wallet_persist_and_recover() {
346346
// should error on wrong internal params
347347
let desc = get_test_wpkh();
348348
let (exp_desc, _) = <Descriptor<DescriptorPublicKey>>::parse_descriptor(secp, desc).unwrap();
349+
let exp_desc = Box::new(exp_desc);
349350
let err = Wallet::load()
350351
.descriptor(KeychainKind::Internal, Some(desc))
351352
.extract_keys()

0 commit comments

Comments
 (0)