runtime-rs: Remove direct implementation of ToString

Fix clippy error:
```
direct implementation of `ToString`
```
by switching to implement Display instead

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
This commit is contained in:
stevenhorsman
2025-01-29 10:51:58 +00:00
parent 730c56af2a
commit fe98d49a29
4 changed files with 25 additions and 24 deletions

View File

@@ -560,11 +560,8 @@ impl PCIeDevice for VfioDevice {
))?; ))?;
hostdev.guest_pci_path = Some(pci_path.clone()); hostdev.guest_pci_path = Some(pci_path.clone());
self.device_options.push(format!( self.device_options
"0000:{}={}", .push(format!("0000:{}={}", hostdev.bus_slot_func, pci_path));
hostdev.bus_slot_func,
pci_path.to_string()
));
} }
Ok(()) Ok(())

View File

@@ -33,9 +33,9 @@ impl PciSlot {
} }
} }
impl ToString for PciSlot { impl std::fmt::Display for PciSlot {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
format!("{:02x}", self.0) write!(f, "{:02x}", self.0)
} }
} }
@@ -116,14 +116,17 @@ impl PciPath {
} }
} }
impl ToString for PciPath { impl std::fmt::Display for PciPath {
// method to format the PciPath into a string fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn to_string(&self) -> String { write!(
self.slots f,
.iter() "{}",
.map(|pci_slot| format!("{:02x}", pci_slot.0)) self.slots
.collect::<Vec<String>>() .iter()
.join("/") .map(|pci_slot| format!("{:02x}", pci_slot.0))
.collect::<Vec<String>>()
.join("/")
)
} }
} }

View File

@@ -1540,13 +1540,14 @@ impl MonitorProtocol {
} }
} }
impl ToString for MonitorProtocol { impl std::fmt::Display for MonitorProtocol {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self { let to_string = match *self {
MonitorProtocol::Hmp => "monitor".to_string(), MonitorProtocol::Hmp => "monitor".to_string(),
MonitorProtocol::QmpPretty => "qmp-pretty".to_string(), MonitorProtocol::QmpPretty => "qmp-pretty".to_string(),
_ => "qmp".to_string(), _ => "qmp".to_string(),
} };
write!(f, "{}", to_string)
} }
} }
@@ -1604,7 +1605,7 @@ impl QmpSocket {
#[async_trait] #[async_trait]
impl ToQemuParams for QmpSocket { impl ToQemuParams for QmpSocket {
async fn qemu_params(&self) -> Result<Vec<String>> { async fn qemu_params(&self) -> Result<Vec<String>> {
let param_qmp = format!("-{}", self.protocol.to_string()); let param_qmp = format!("-{}", self.protocol);
let mut params: Vec<String> = Vec::new(); let mut params: Vec<String> = Vec::new();

View File

@@ -78,9 +78,9 @@ pub struct ContainerID {
pub container_id: String, pub container_id: String,
} }
impl ToString for ContainerID { impl std::fmt::Display for ContainerID {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.container_id.clone() write!(f, "{}", self.container_id)
} }
} }