Skip to content

Commit a89edba

Browse files
committed
Configure group_imports
Configure `group_imports = "StdExternalCrate"`. The benefit of this option is that it increases uniformity in the code base over the default "Preserve", while saving devs needing to think about where they place their import statements (for those that do not use tooling to add them).
1 parent ccdef6f commit a89edba

36 files changed

+152
-140
lines changed

examples/htlc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
//! Example: Create an HTLC with miniscript using the policy compiler
1616
17+
use std::str::FromStr;
18+
1719
use bitcoin::Network;
1820
use miniscript::descriptor::Wsh;
1921
use miniscript::policy::{Concrete, Liftable};
2022
use miniscript::DescriptorTrait;
21-
use std::str::FromStr;
2223

2324
fn main() {
2425
// HTLC policy with 10:1 odds for happy (co-operative) case compared to uncooperative case.

examples/parse.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
//! Example: Parsing a descriptor from a string.
1616
17-
use miniscript::{descriptor::DescriptorType, Descriptor, DescriptorTrait};
1817
use std::str::FromStr;
1918

19+
use miniscript::{descriptor::DescriptorType, Descriptor, DescriptorTrait};
20+
2021
fn main() {
2122
let desc = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(
2223
"wsh(c:pk_k(020202020202020202020202020202020202020202020202020202020202020202))",

examples/sign_multisig.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
//! Example: Signing a 2-of-3 multisignature.
1616
17+
use std::collections::HashMap;
18+
use std::str::FromStr;
19+
1720
use bitcoin::blockdata::witness::Witness;
1821
use bitcoin::secp256k1;
1922
use miniscript::DescriptorTrait;
20-
use std::collections::HashMap;
21-
use std::str::FromStr;
2223

2324
fn main() {
2425
let mut tx = spending_transaction();

examples/verify_tx.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
//! Example: Verifying a signed transaction.
1616
17+
use std::str::FromStr;
18+
1719
use bitcoin::consensus::Decodable;
1820
use bitcoin::secp256k1::{self, Secp256k1};
1921
use bitcoin::util::sighash;
2022
use miniscript::interpreter::KeySigPair;
21-
use std::str::FromStr;
2223

2324
fn main() {
2425
//

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ where_single_line = false
2828
imports_indent = "Block"
2929
imports_layout = "Mixed"
3030
imports_granularity = "Preserve"
31-
group_imports = "Preserve"
31+
group_imports = "StdExternalCrate" # Default "Preserve"
3232
reorder_imports = true
3333
reorder_modules = true
3434
reorder_impl_items = false

src/descriptor/bare.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ use std::{fmt, str::FromStr};
2222

2323
use bitcoin::{self, blockdata::script, Script};
2424

25+
use super::{
26+
checksum::{desc_checksum, verify_checksum},
27+
DescriptorTrait,
28+
};
2529
use crate::expression::{self, FromTree};
2630
use crate::miniscript::context::ScriptContext;
2731
use crate::policy::{semantic, Liftable};
@@ -31,11 +35,6 @@ use crate::{
3135
TranslatePk,
3236
};
3337

34-
use super::{
35-
checksum::{desc_checksum, verify_checksum},
36-
DescriptorTrait,
37-
};
38-
3938
/// Create a Bare Descriptor. That is descriptor that is
4039
/// not wrapped in sh or wsh. This covers the Pk descriptor
4140
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]

src/descriptor/checksum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ pub(super) fn verify_checksum(s: &str) -> Result<&str, Error> {
100100
}
101101
#[cfg(test)]
102102
mod test {
103-
use super::*;
104103
use std::str;
105104

105+
use super::*;
106+
106107
macro_rules! check_expected {
107108
($desc: expr, $checksum: expr) => {
108109
assert_eq!(desc_checksum($desc).unwrap(), $checksum);

src/descriptor/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,11 +796,11 @@ impl ToPublicKey for DerivedDescriptorKey {
796796

797797
#[cfg(test)]
798798
mod test {
799-
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};
799+
use std::str::FromStr;
800800

801801
use bitcoin::secp256k1;
802802

803-
use std::str::FromStr;
803+
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};
804804

805805
#[test]
806806
fn parse_descriptor_key_errors() {

src/descriptor/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -857,26 +857,27 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");
857857

858858
#[cfg(test)]
859859
mod tests {
860-
use super::checksum::desc_checksum;
861-
use super::tr::Tr;
862-
use super::*;
863-
use crate::descriptor::key::Wildcard;
864-
use crate::descriptor::{DescriptorPublicKey, DescriptorSecretKey, DescriptorXKey, SinglePub};
865-
use crate::hex_script;
866-
use crate::{Descriptor, DummyKey, Error, Miniscript, Satisfier, TranslatePk2};
860+
use std::cmp;
861+
use std::collections::HashMap;
862+
use std::str::FromStr;
863+
867864
use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
868865
use bitcoin::blockdata::script::Instruction;
869866
use bitcoin::blockdata::{opcodes, script};
870867
use bitcoin::hashes::hex::{FromHex, ToHex};
871868
use bitcoin::hashes::{hash160, sha256};
872869
use bitcoin::util::bip32;
873870
use bitcoin::{self, secp256k1, EcdsaSighashType, PublicKey};
874-
use std::cmp;
875-
use std::collections::HashMap;
876-
use std::str::FromStr;
877871

872+
use super::checksum::desc_checksum;
873+
use super::tr::Tr;
874+
use super::*;
875+
use crate::descriptor::key::Wildcard;
876+
use crate::descriptor::{DescriptorPublicKey, DescriptorSecretKey, DescriptorXKey, SinglePub};
877+
use crate::hex_script;
878878
#[cfg(feature = "compiler")]
879879
use crate::policy;
880+
use crate::{Descriptor, DummyKey, Error, Miniscript, Satisfier, TranslatePk2};
880881

881882
type StdDescriptor = Descriptor<PublicKey>;
882883
const TEST_PK: &'static str =

src/descriptor/pretaproot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,12 @@ serde_string_impl_pk!(PreTaprootDescriptor, "a pre-taproot script descriptor");
241241
pub(crate) mod traits {
242242
use bitcoin::Script;
243243

244+
use super::PreTaprootDescriptor;
244245
use crate::{
245246
descriptor::{Pkh, Sh, Wpkh, Wsh},
246247
DescriptorTrait, MiniscriptKey, ToPublicKey,
247248
};
248249

249-
use super::PreTaprootDescriptor;
250-
251250
/// A general trait for Pre taproot bitcoin descriptor.
252251
/// Similar to [`DescriptorTrait`], but `explicit_script` and `script_code` methods cannot fail
253252
pub trait PreTaprootDescriptorTrait<Pk: MiniscriptKey>: DescriptorTrait<Pk> {

0 commit comments

Comments
 (0)