25 releases (7 stable)
Uses new Rust 2024
| new 1.1.1 | Feb 26, 2026 |
|---|---|
| 1.0.3 | Jan 3, 2026 |
| 1.0.2 | Dec 29, 2025 |
| 1.0.1 | Sep 22, 2025 |
| 0.1.1 | Mar 31, 2025 |
#1912 in Parser implementations
1,631 downloads per month
Used in 8 crates
(2 directly)
36KB
394 lines
Utilities for parsing and emitting strings in the the cpulist format often used by Linux
utilities that work with processor IDs, memory region IDs and similar numeric hardware
identifiers.
Example cpulist string: 0-9,32-35,40.
This is part of the Folo project that provides mechanisms for high-performance hardware-aware programming in Rust.
Format
The value is a comma-separated list of zero or more integers or integer ranges, where each item is either:
- a single integer (e.g.
1) - a range of integers (e.g.
2-4) - a range of integers with a stride (step size) operator (e.g.
5-9:2which is equivalent to5,7,9)
Whitespace or extra characters are not allowed anywhere in the string.
The identifiers in the list are of size u32.
Example
Basic conversion from/to strings:
let selected_processors = cpulist::parse("0-9,32-35,40").unwrap();
assert_eq!(
selected_processors,
vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 32, 33, 34, 35, 40]
);
println!("Selected processors: {selected_processors:?}");
println!("As cpulist: {}", cpulist::emit(selected_processors));
The stride operator is also supported for parsing:
let evens = cpulist::parse("0-16:2").unwrap();
let odds = cpulist::parse("1-16:2").unwrap();
let all = cpulist::emit(odds.iter().chain(evens.iter()).copied());
println!("Evens: {evens:?}");
println!("Odds: {odds:?}");
println!("All as cpulist: {all}");
Utilities for parsing and emitting strings in the the cpulist format often used by Linux
utilities that work with processor IDs, memory region IDs and similar numeric hardware
identifiers.
Example cpulist string: 0,1,2-4,5-9:2,6-10:2
let selected_processors = cpulist::parse("0-9,32-35,40").unwrap();
assert_eq!(
selected_processors,
vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 32, 33, 34, 35, 40]
);
println!("Selected processors: {selected_processors:?}");
println!("As cpulist: {}", cpulist::emit(selected_processors));
See also
More details in the package documentation.
This is part of the Folo project that provides mechanisms for high-performance hardware-aware programming in Rust.
Dependencies
~0.6–1MB
~22K SLoC