| 1 | // examples/arch.rs |
| 2 | // * use `cargo run --example arch` to execute this example |
| 3 | |
| 4 | // spell-checker:ignore (API) nodename osname sysname |
| 5 | |
| 6 | use platform_inforust-analyzer cargo platform-info 2.0.5 crate/::{PlatformInforust-analyzer cargo platform-info 2.0.5 lib_impl/target/PlatformInfo#, PlatformInfoAPIrust-analyzer cargo platform-info 2.0.5 PlatformInfoAPI#, UNameAPIrust-analyzer cargo platform-info 2.0.5 UNameAPI#}; |
| 7 | |
| 8 | fn mainrust-analyzer cargo platform-info 2.0.5 main().() { |
| 9 | let info = PlatformInforust-analyzer cargo platform-info 2.0.5 lib_impl/target/PlatformInfo#::newrust-analyzer cargo platform-info 2.0.5 lib_impl/target/impl#[PlatformInfo][PlatformInfoAPI]new().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|err| { |
| 10 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Unable to determine platform info: {err}"); |
| 11 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().(1); |
| 12 | }); |
| 13 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!( |
| 14 | "{}", |
| 15 | match info.machinerust-analyzer cargo platform-info 2.0.5 lib_impl/target/impl#[PlatformInfo][UNameAPI]machine().().to_os_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_os_string().().into_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString]into_string().() { |
| 16 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => s, |
| 17 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(os_s) => { |
| 18 | let s = os_s.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().(); |
| 19 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("machine = [{}]'{:?}' => '{}'", os_s.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]len().(), os_s, s); |
| 20 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<Cow<'a, str>>`]from().(s) |
| 21 | } |
| 22 | } |
| 23 | ); |
| 24 | } |