From c50a4096f7eadc8eb49e726216bba2cf44f5e9a7 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Tue, 28 May 2024 20:48:26 -0500 Subject: [PATCH] fix(clippy): direct implementation of ToString --- src/lib.rs | 1 + src/types.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d986b1c..fa47492 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,7 @@ #[cfg(test)] #[macro_use] extern crate serial_test; +extern crate core; pub use interface::HWIClient; diff --git a/src/types.rs b/src/types.rs index 4f368ef..db8ef8e 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,6 @@ +use core::fmt; use std::convert::TryFrom; +use std::fmt::{Display, Formatter}; use std::ops::Deref; use std::str::FromStr; @@ -260,9 +262,9 @@ where } } -impl ToString for HWIDeviceType { - fn to_string(&self) -> String { - match self { +impl Display for HWIDeviceType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let name = match self { Self::Ledger => String::from("ledger"), Self::Trezor => String::from("trezor"), Self::BitBox01 => String::from("digitalbitbox"), @@ -271,7 +273,8 @@ impl ToString for HWIDeviceType { Self::Coldcard => String::from("coldcard"), Self::Jade => String::from("jade"), Self::Other(name) => name.to_string(), - } + }; + fmt::Display::fmt(&name, f) } }