diff --git a/src/runtime-rs/crates/hypervisor/src/device/driver/vfio.rs b/src/runtime-rs/crates/hypervisor/src/device/driver/vfio.rs index 29837010d9..eaad098d42 100644 --- a/src/runtime-rs/crates/hypervisor/src/device/driver/vfio.rs +++ b/src/runtime-rs/crates/hypervisor/src/device/driver/vfio.rs @@ -560,11 +560,8 @@ impl PCIeDevice for VfioDevice { ))?; hostdev.guest_pci_path = Some(pci_path.clone()); - self.device_options.push(format!( - "0000:{}={}", - hostdev.bus_slot_func, - pci_path.to_string() - )); + self.device_options + .push(format!("0000:{}={}", hostdev.bus_slot_func, pci_path)); } Ok(()) diff --git a/src/runtime-rs/crates/hypervisor/src/device/pci_path.rs b/src/runtime-rs/crates/hypervisor/src/device/pci_path.rs index 2d0be7647f..a774f5038e 100644 --- a/src/runtime-rs/crates/hypervisor/src/device/pci_path.rs +++ b/src/runtime-rs/crates/hypervisor/src/device/pci_path.rs @@ -33,9 +33,9 @@ impl PciSlot { } } -impl ToString for PciSlot { - fn to_string(&self) -> String { - format!("{:02x}", self.0) +impl std::fmt::Display for PciSlot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:02x}", self.0) } } @@ -116,14 +116,17 @@ impl PciPath { } } -impl ToString for PciPath { - // method to format the PciPath into a string - fn to_string(&self) -> String { - self.slots - .iter() - .map(|pci_slot| format!("{:02x}", pci_slot.0)) - .collect::>() - .join("/") +impl std::fmt::Display for PciPath { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + self.slots + .iter() + .map(|pci_slot| format!("{:02x}", pci_slot.0)) + .collect::>() + .join("/") + ) } } diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs index 8263c033ad..d41c891ad3 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs @@ -1540,13 +1540,14 @@ impl MonitorProtocol { } } -impl ToString for MonitorProtocol { - fn to_string(&self) -> String { - match *self { +impl std::fmt::Display for MonitorProtocol { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let to_string = match *self { MonitorProtocol::Hmp => "monitor".to_string(), MonitorProtocol::QmpPretty => "qmp-pretty".to_string(), _ => "qmp".to_string(), - } + }; + write!(f, "{}", to_string) } } @@ -1604,7 +1605,7 @@ impl QmpSocket { #[async_trait] impl ToQemuParams for QmpSocket { async fn qemu_params(&self) -> Result> { - let param_qmp = format!("-{}", self.protocol.to_string()); + let param_qmp = format!("-{}", self.protocol); let mut params: Vec = Vec::new(); diff --git a/src/runtime-rs/crates/runtimes/common/src/types/mod.rs b/src/runtime-rs/crates/runtimes/common/src/types/mod.rs index d7d81dcde6..3accf34581 100644 --- a/src/runtime-rs/crates/runtimes/common/src/types/mod.rs +++ b/src/runtime-rs/crates/runtimes/common/src/types/mod.rs @@ -78,9 +78,9 @@ pub struct ContainerID { pub container_id: String, } -impl ToString for ContainerID { - fn to_string(&self) -> String { - self.container_id.clone() +impl std::fmt::Display for ContainerID { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.container_id) } }