parse_topology_string

Function parse_topology_string 

Source
pub fn parse_topology_string(topology: &str) -> Result<(u32, u32, u32, u32)>
Expand description

Parse a comma-separated topology string into its four dimensions: (numa_nodes, llcs, cores, threads). The canonical format is "numa_nodes,llcs,cores,threads" — the same shape accepted by the ktstr shell --topology and cargo ktstr shell --topology flags.

Validation:

  • Exactly four comma-separated components are required.
  • Each component must parse as u32. A parse failure names the failing field explicitly (e.g. "invalid llcs value: 'abc'") so the user can see which dimension they mistyped without counting commas.
  • Every dimension must be at least 1 — a zero in any position produces an unusable VM topology, so we reject it up front.

Consolidating the parse + validate in one helper eliminates the identical 4-arm parts[i].parse().map_err(...) block that the two binary entry points (src/bin/ktstr.rs Command::Shell and src/bin/cargo_ktstr/misc/shell.rs run_shell) would otherwise drift on. Error shape is anyhow::Error; callers that need a String (like cargo-ktstr’s Result<(), String> surface) bridge via .map_err(|e| format!("{e:#}")) at the call site.