| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/; |
| 2 | use 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/; |
| 3 | use udevrsrust-analyzer cargo udevrs 0.4.0 crate/::{udev_newrust-analyzer cargo udevrs 0.4.0 udev_new()., UdevHwdbrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#}; |
| 4 | |
| 5 | /// Simple program to query the systemd hwdb like `systemd-hwdb` |
| 6 | fn mainrust-analyzer cargo udevrs 0.4.0 main().() { |
| 7 | env_loggerrust-analyzer cargo env_logger 0.11.6 crate/::initrust-analyzer cargo env_logger 0.11.6 logger/init().(); |
| 8 | let args: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/args().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 9 | |
| 10 | if args.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().2 { |
| 11 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Usage: {} <hwdb_key>", args[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().); |
| 12 | 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); |
| 13 | } |
| 14 | |
| 15 | let key = &args[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 16 | |
| 17 | // Initialize the Hwdb |
| 18 | let mut hwdb = match UdevHwdbrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#::newrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]new().(udev_newrust-analyzer cargo udevrs 0.4.0 udev_new().()) { |
| 19 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(db) => db, |
| 20 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 21 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Failed to initialize hwdb: {}", e); |
| 22 | 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); |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | // Query the hwdb with the provided key |
| 27 | logrust-analyzer cargo log 0.4.25 crate/::inforust-analyzer cargo log 0.4.25 macros/info!!("Querying hwdb with key: {}", key); |
| 28 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(properties) = hwdb.queryrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]query().(key) { |
| 29 | properties |
| 30 | .iterrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]iter().() |
| 31 | .for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(|e| printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}: {}", e.namerust-analyzer cargo udevrs 0.4.0 list/impl#[UdevEntry]name().(), e.valuerust-analyzer cargo udevrs 0.4.0 list/impl#[UdevEntry]value().())); |
| 32 | }; |
| 33 | } |