Files
platform-info/examples/ex.rs
T
Cả thế giới là Rust 2271b98c1b Add processor() method to UNameAPI trait (#96)
* Add processor() method to UNameAPI trait

Implements processor type mapping to provide GNU coreutils-compatible
processor information, addressing uutils/coreutils#8659.

Changes:
- Add processor() method to UNameAPI trait with comprehensive docs
- Implement map_processor() helper in lib_impl for arch-to-processor mapping
- Add processor field and implementation to all platform modules (Unix, Windows, unknown)
- Include platform-specific tests verifying correct processor mappings
- Update example code to demonstrate processor() usage
- Add workspace declaration to Cargo.toml to prevent parent workspace inheritance

Processor mapping behavior:
- macOS: arm64 → arm
- Linux: aarch64 → aarch64 (passthrough)
- x86_64/amd64 → x86_64
- i386/i486/i586/i686 → i686
- ARMv6/v7/v8 variants → arm
- Unknown architectures pass through unchanged (better than "unknown")

This provides the foundation for uutils/coreutils to migrate from its
local processor mapping implementation, consolidating platform knowledge
in the appropriate abstraction layer.

Ref: uutils/coreutils#8659

* docs: update README to include processor() method

Add processor() to example code and expected output as requested by @sylvestre

* docs: clarify processor() vs machine() difference and add comprehensive tests

Address review feedback:
- Remove incomplete archive.is placeholder
- Add detailed documentation explaining how processor() differs from machine()
- Include comparison table showing platform-specific behavior
- Add comprehensive unit test for map_processor() covering all branches
- Improves test coverage from 66.66% to 100% in lib_impl.rs
2025-11-27 14:41:41 +01:00

20 lines
766 B
Rust

// examples/ex.rs
// * use `cargo run --example ex` to execute this example
// spell-checker:ignore (API) nodename osname sysname
use platform_info::{PlatformInfo, PlatformInfoAPI, UNameAPI};
fn main() {
let info = PlatformInfo::new().expect("Unable to determine platform info");
// println!("info={:#?}", info); // note: info *may* contain extra platform-specific fields
println!("{}", info.sysname().to_string_lossy());
println!("{}", info.nodename().to_string_lossy());
println!("{}", info.release().to_string_lossy());
println!("{}", info.version().to_string_lossy());
println!("{}", info.machine().to_string_lossy());
println!("{}", info.processor().to_string_lossy());
println!("{}", info.osname().to_string_lossy());
}