#memory-region #parser #format #processor #hardware-aware #emit

cpulist

Parse and emit the Linux 'cpulist' data format used to list processors, memory regions and similar entities

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

Download history 295/week @ 2025-11-06 234/week @ 2025-11-13 316/week @ 2025-11-20 254/week @ 2025-11-27 220/week @ 2025-12-04 242/week @ 2025-12-11 208/week @ 2025-12-18 211/week @ 2025-12-25 323/week @ 2026-01-01 295/week @ 2026-01-08 487/week @ 2026-01-15 542/week @ 2026-01-22 184/week @ 2026-01-29 203/week @ 2026-02-05 468/week @ 2026-02-12 690/week @ 2026-02-19

1,631 downloads per month
Used in 8 crates (2 directly)

MIT license

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:2 which is equivalent to 5,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