Skip to content

Commit 4eec7a8

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): implement Display trait for WrapDescriptor
Improve code quality by implementing the Display trait for WrapDescriptor and refactoring the to_string method to use it, following best practices. Added an allow annotation for clippy warning about shadowing Display trait. Issue: BTC-2652 Co-authored-by: llm-git <[email protected]>
1 parent 491675c commit 4eec7a8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

packages/wasm-utxo/src/descriptor.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use miniscript::bitcoin::secp256k1::{Secp256k1, Signing};
44
use miniscript::bitcoin::ScriptBuf;
55
use miniscript::descriptor::KeyMap;
66
use miniscript::{DefiniteDescriptorKey, Descriptor, DescriptorPublicKey};
7+
use std::fmt;
78
use std::str::FromStr;
89
use wasm_bindgen::prelude::*;
910

@@ -27,12 +28,9 @@ impl WrapDescriptor {
2728
}
2829

2930
#[wasm_bindgen(js_name = toString)]
31+
#[allow(clippy::inherent_to_string_shadow_display)]
3032
pub fn to_string(&self) -> String {
31-
match &self.0 {
32-
WrapDescriptorEnum::Derivable(desc, _) => desc.to_string(),
33-
WrapDescriptorEnum::Definite(desc) => desc.to_string(),
34-
WrapDescriptorEnum::String(desc) => desc.to_string(),
35-
}
33+
format!("{}", self)
3634
}
3735

3836
#[wasm_bindgen(js_name = hasWildcard)]
@@ -199,6 +197,16 @@ impl WrapDescriptor {
199197
}
200198
}
201199

200+
impl fmt::Display for WrapDescriptor {
201+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
202+
match &self.0 {
203+
WrapDescriptorEnum::Derivable(desc, _) => write!(f, "{}", desc),
204+
WrapDescriptorEnum::Definite(desc) => write!(f, "{}", desc),
205+
WrapDescriptorEnum::String(desc) => write!(f, "{}", desc),
206+
}
207+
}
208+
}
209+
202210
impl FromStr for WrapDescriptor {
203211
type Err = WasmMiniscriptError;
204212
fn from_str(s: &str) -> Result<Self, Self::Err> {

0 commit comments

Comments
 (0)