Skip to content

Commit 4ede644

Browse files
committed
Use Self::Foo instead of importing error variants
In the Error impl there is a combination of the use of: - use FooError::*; - use FooError as E; - Self::FooVariant Remove all imports and use Self::FooVariant in all Error impl in types.
1 parent 0e94709 commit 4ede644

File tree

32 files changed

+1065
-1521
lines changed

32 files changed

+1065
-1521
lines changed

types/src/lib.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,9 @@ pub enum NumericError {
7777

7878
impl fmt::Display for NumericError {
7979
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
80-
use NumericError::*;
81-
8280
match *self {
83-
Negative{ ref field, value } => write!(f, "expected an unsigned numeric value however the value was negative (field name: {} value: {})", field, value),
84-
Overflow { ref field, value } => write!(f, "a value larger than `u32::MAX` was unexpectedly encountered (field name: {} Value: {})", field, value),
81+
Self::Negative{ ref field, value } => write!(f, "expected an unsigned numeric value however the value was negative (field name: {} value: {})", field, value),
82+
Self::Overflow { ref field, value } => write!(f, "a value larger than `u32::MAX` was unexpectedly encountered (field name: {} Value: {})", field, value),
8583
}
8684
}
8785
}
@@ -222,23 +220,21 @@ pub enum ScriptPubkeyError {
222220

223221
impl fmt::Display for ScriptPubkeyError {
224222
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
225-
use ScriptPubkeyError::*;
226223
match *self {
227-
Hex(ref e) => write_err!(f, "conversion of the `hex` field failed"; e),
228-
Address(ref e) => write_err!(f, "conversion of the `address` field failed"; e),
229-
Addresses(ref e) => write_err!(f, "conversion of the `addresses` field failed"; e),
224+
Self::Hex(ref e) => write_err!(f, "conversion of the `hex` field failed"; e),
225+
Self::Address(ref e) => write_err!(f, "conversion of the `address` field failed"; e),
226+
Self::Addresses(ref e) => write_err!(f, "conversion of the `addresses` field failed"; e),
230227
}
231228
}
232229
}
233230

234231
#[cfg(feature = "std")]
235232
impl std::error::Error for ScriptPubkeyError {
236233
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
237-
use ScriptPubkeyError::*;
238234
match *self {
239-
Hex(ref e) => Some(e),
240-
Address(ref e) => Some(e),
241-
Addresses(ref e) => Some(e),
235+
Self::Hex(ref e) => Some(e),
236+
Self::Address(ref e) => Some(e),
237+
Self::Addresses(ref e) => Some(e),
242238
}
243239
}
244240
}

types/src/psbt/error.rs

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ pub enum RawTransactionError {
1818

1919
impl fmt::Display for RawTransactionError {
2020
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21-
use RawTransactionError as E;
22-
2321
match *self {
24-
E::Inputs(ref e) =>
22+
Self::Inputs(ref e) =>
2523
write_err!(f, "conversion of one of the transaction inputs failed"; e),
26-
E::Outputs(ref e) =>
24+
Self::Outputs(ref e) =>
2725
write_err!(f, "conversion of one of the transaction outputs failed"; e),
2826
}
2927
}
@@ -32,11 +30,9 @@ impl fmt::Display for RawTransactionError {
3230
#[cfg(feature = "std")]
3331
impl std::error::Error for RawTransactionError {
3432
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
35-
use RawTransactionError as E;
36-
3733
match *self {
38-
E::Inputs(ref e) => Some(e),
39-
E::Outputs(ref e) => Some(e),
34+
Self::Inputs(ref e) => Some(e),
35+
Self::Outputs(ref e) => Some(e),
4036
}
4137
}
4238
}
@@ -54,13 +50,11 @@ pub enum RawTransactionInputError {
5450

5551
impl fmt::Display for RawTransactionInputError {
5652
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57-
use RawTransactionInputError as E;
58-
5953
match *self {
60-
E::Txid(ref e) => write_err!(f, "conversion of the input `txid` field failed"; e),
61-
E::ScriptSig(ref e) =>
54+
Self::Txid(ref e) => write_err!(f, "conversion of the input `txid` field failed"; e),
55+
Self::ScriptSig(ref e) =>
6256
write_err!(f, "conversion of the input `script_sig` field failed"; e),
63-
E::Witness(ref e) =>
57+
Self::Witness(ref e) =>
6458
write_err!(f, "conversion of one of the `witness` hex strings failed"; e),
6559
}
6660
}
@@ -69,12 +63,10 @@ impl fmt::Display for RawTransactionInputError {
6963
#[cfg(feature = "std")]
7064
impl std::error::Error for RawTransactionInputError {
7165
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
72-
use RawTransactionInputError as E;
73-
7466
match *self {
75-
E::Txid(ref e) => Some(e),
76-
E::ScriptSig(ref e) => Some(e),
77-
E::Witness(ref e) => Some(e),
67+
Self::Txid(ref e) => Some(e),
68+
Self::ScriptSig(ref e) => Some(e),
69+
Self::Witness(ref e) => Some(e),
7870
}
7971
}
8072
}
@@ -90,11 +82,9 @@ pub enum RawTransactionOutputError {
9082

9183
impl fmt::Display for RawTransactionOutputError {
9284
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
93-
use RawTransactionOutputError as E;
94-
9585
match *self {
96-
E::Value(ref e) => write_err!(f, "conversion of the output `value` field failed"; e),
97-
E::ScriptPubkey(ref e) =>
86+
Self::Value(ref e) => write_err!(f, "conversion of the output `value` field failed"; e),
87+
Self::ScriptPubkey(ref e) =>
9888
write_err!(f, "conversion of the output `script_pubkey` field failed"; e),
9989
}
10090
}
@@ -103,11 +93,9 @@ impl fmt::Display for RawTransactionOutputError {
10393
#[cfg(feature = "std")]
10494
impl std::error::Error for RawTransactionOutputError {
10595
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
106-
use RawTransactionOutputError as E;
107-
10896
match *self {
109-
E::Value(ref e) => Some(e),
110-
E::ScriptPubkey(ref e) => Some(e),
97+
Self::Value(ref e) => Some(e),
98+
Self::ScriptPubkey(ref e) => Some(e),
11199
}
112100
}
113101
}
@@ -123,11 +111,9 @@ pub enum WitnessUtxoError {
123111

124112
impl fmt::Display for WitnessUtxoError {
125113
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
126-
use WitnessUtxoError as E;
127-
128114
match *self {
129-
E::Amount(ref e) => write_err!(f, "conversion of the `amount` field failed"; e),
130-
E::ScriptPubkey(ref e) =>
115+
Self::Amount(ref e) => write_err!(f, "conversion of the `amount` field failed"; e),
116+
Self::ScriptPubkey(ref e) =>
131117
write_err!(f, "conversion of the `script_pubkey` field failed"; e),
132118
}
133119
}
@@ -136,11 +122,9 @@ impl fmt::Display for WitnessUtxoError {
136122
#[cfg(feature = "std")]
137123
impl std::error::Error for WitnessUtxoError {
138124
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
139-
use WitnessUtxoError as E;
140-
141125
match *self {
142-
E::Amount(ref e) => Some(e),
143-
E::ScriptPubkey(ref e) => Some(e),
126+
Self::Amount(ref e) => Some(e),
127+
Self::ScriptPubkey(ref e) => Some(e),
144128
}
145129
}
146130
}
@@ -156,24 +140,20 @@ pub enum PartialSignatureError {
156140

157141
impl fmt::Display for PartialSignatureError {
158142
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
159-
use PartialSignatureError as E;
160-
161143
match *self {
162-
E::PublicKey(ref e) =>
144+
Self::PublicKey(ref e) =>
163145
write_err!(f, "partial sigs key-value pair parse pubkey failed"; e),
164-
E::Signature(ref e) => write_err!(f, "partial sigs key-value pair parse sig failed"; e),
146+
Self::Signature(ref e) => write_err!(f, "partial sigs key-value pair parse sig failed"; e),
165147
}
166148
}
167149
}
168150

169151
#[cfg(feature = "std")]
170152
impl std::error::Error for PartialSignatureError {
171153
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
172-
use PartialSignatureError as E;
173-
174154
match *self {
175-
E::PublicKey(ref e) => Some(e),
176-
E::Signature(ref e) => Some(e),
155+
Self::PublicKey(ref e) => Some(e),
156+
Self::Signature(ref e) => Some(e),
177157
}
178158
}
179159
}
@@ -191,26 +171,22 @@ pub enum Bip32DerivError {
191171

192172
impl fmt::Display for Bip32DerivError {
193173
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
194-
use Bip32DerivError as E;
195-
196174
match *self {
197-
E::Pubkey(ref e) => write_err!(f, "conversion of the pubkey failed"; e),
198-
E::MasterFingerprint(ref e) =>
175+
Self::Pubkey(ref e) => write_err!(f, "conversion of the pubkey failed"; e),
176+
Self::MasterFingerprint(ref e) =>
199177
write_err!(f, "conversion of the `master_fingerprint` field failed"; e),
200-
E::Path(ref e) => write_err!(f, "conversion of the `path` field failed"; e),
178+
Self::Path(ref e) => write_err!(f, "conversion of the `path` field failed"; e),
201179
}
202180
}
203181
}
204182

205183
#[cfg(feature = "std")]
206184
impl std::error::Error for Bip32DerivError {
207185
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
208-
use Bip32DerivError as E;
209-
210186
match *self {
211-
E::Pubkey(ref e) => Some(e),
212-
E::MasterFingerprint(ref e) => Some(e),
213-
E::Path(ref e) => Some(e),
187+
Self::Pubkey(ref e) => Some(e),
188+
Self::MasterFingerprint(ref e) => Some(e),
189+
Self::Path(ref e) => Some(e),
214190
}
215191
}
216192
}

0 commit comments

Comments
 (0)