Skip to content

Commit

Permalink
replace as_str impl with derive(AsRefStr)
Browse files Browse the repository at this point in the history
Signed-off-by: bg-furiosa <[email protected]>
  • Loading branch information
bg-furiosa committed Apr 12, 2024
1 parent eb89e59 commit 5d25684
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
2 changes: 1 addition & 1 deletion device-api/bin/show_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn main() -> Result<(), DeviceError> {
let mut row = vec![device1.to_string().cell()];
for device2 in devices.iter() {
let link_type = topology.get_link_type(device1, device2);
row.push(link_type.as_str().cell());
row.push(link_type.as_ref().cell());
}
rows.push(row);
}
Expand Down
16 changes: 3 additions & 13 deletions device-api/src/topology/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(warnings)]
use std::collections::BTreeMap;

use strum_macros::AsRefStr;

use crate::topology::hwloc::{Hwloc, HwlocTopology};
use crate::topology::hwloc_binding::*;
use crate::topology::LinkType::*;
Expand All @@ -9,7 +11,7 @@ use crate::{Device, DeviceResult};
mod hwloc;
mod hwloc_binding;

#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(AsRefStr, Clone, Copy, Debug, PartialEq)]
pub enum LinkType {
// LinkTypeUnknown unknown
LinkTypeUnknown = 0,
Expand All @@ -31,18 +33,6 @@ pub enum LinkType {
LinkTypeSoc = 70,
}

impl LinkType {
pub fn as_str(&self) -> &'static str {
match self {
LinkTypeUnknown => "LinkTypeUnknown",
LinkTypeInterconnect => "LinkTypeInterconnect",
LinkTypeCPU => "LinkTypeCPU",
LinkTypeHostBridge => "LinkTypeHostBridge",
LinkTypeSoc => "LinkTypeSoc",
}
}
}

pub trait HardwareTopologyHint {
fn get_hw_topology_hint(&self) -> String;
}
Expand Down

0 comments on commit 5d25684

Please sign in to comment.