Skip to content

Commit 187a494

Browse files
committed
feat: implement Display for LoadMismatch
1 parent 0acd802 commit 187a494

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

wallet/src/wallet/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,44 @@ pub enum LoadMismatch {
232232
},
233233
}
234234

235+
impl fmt::Display for LoadMismatch {
236+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
237+
match self {
238+
LoadMismatch::Network { loaded, expected } => {
239+
write!(
240+
f,
241+
"Network mismatch: loaded {}, expected {}",
242+
loaded, expected
243+
)
244+
}
245+
LoadMismatch::Genesis { loaded, expected } => {
246+
write!(
247+
f,
248+
"Genesis hash mismatch: loaded {}, expected {}",
249+
loaded, expected
250+
)
251+
}
252+
LoadMismatch::Descriptor {
253+
keychain,
254+
loaded,
255+
expected,
256+
} => {
257+
write!(
258+
f,
259+
"Descriptor mismatch for {} keychain: loaded {}, expected {}",
260+
keychain,
261+
loaded
262+
.as_ref()
263+
.map_or("None".to_string(), |d| d.to_string()),
264+
expected
265+
.as_ref()
266+
.map_or("None".to_string(), |d| d.to_string())
267+
)
268+
}
269+
}
270+
}
271+
}
272+
235273
impl From<LoadMismatch> for LoadError {
236274
fn from(mismatch: LoadMismatch) -> Self {
237275
Self::Mismatch(mismatch)

0 commit comments

Comments
 (0)