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());
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(())

View File

@@ -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::<Vec<String>>()
.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::<Vec<String>>()
.join("/")
)
}
}

View File

@@ -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<Vec<String>> {
let param_qmp = format!("-{}", self.protocol.to_string());
let param_qmp = format!("-{}", self.protocol);
let mut params: Vec<String> = Vec::new();

View File

@@ -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)
}
}