Debian Codegraph @

examples/list_devices.rs

raw symbols SCIP
1 extern crate libudev_sys as udevrust-analyzer cargo libudev-sys 0.1.4 udev/;
2 extern crate libcrust-analyzer cargo libudev-sys 0.1.4 libc/;
3
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/;
6
7 use libcrust-analyzer cargo libc 0.2.189 crate/::c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#;
8
9 fn mainrust-analyzer cargo libudev-sys 0.1.4 main().() {
10 unsafe {
11 let udev = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_newrust-analyzer cargo libudev-sys 0.1.4 udev_new().();
12
13 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().udev.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() {
14 enumerate_devicesrust-analyzer cargo libudev-sys 0.1.4 enumerate_devices().(udev);
15 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_unrefrust-analyzer cargo libudev-sys 0.1.4 udev_unref().(udev);
16 }
17 }
18 }
19
20 unsafe fn enumerate_devicesrust-analyzer cargo libudev-sys 0.1.4 enumerate_devices().(udev: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udevrust-analyzer cargo libudev-sys 0.1.4 udev#) {
21 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_refrust-analyzer cargo libudev-sys 0.1.4 udev_ref().(udev);
22
23 let enumerate = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_enumerate_newrust-analyzer cargo libudev-sys 0.1.4 udev_enumerate_new().(udev);
24
25 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().enumerate.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() {
26 list_devicesrust-analyzer cargo libudev-sys 0.1.4 list_devices().(enumerate);
27 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_enumerate_unrefrust-analyzer cargo libudev-sys 0.1.4 udev_enumerate_unref().(enumerate);
28 }
29
30 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_unrefrust-analyzer cargo libudev-sys 0.1.4 udev_unref().(udev);
31 }
32
33 unsafe fn list_devicesrust-analyzer cargo libudev-sys 0.1.4 list_devices().(enumerate: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_enumeraterust-analyzer cargo libudev-sys 0.1.4 udev_enumerate#) {
34 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_enumerate_refrust-analyzer cargo libudev-sys 0.1.4 udev_enumerate_ref().(enumerate);
35
36 if udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_enumerate_scan_devicesrust-analyzer cargo libudev-sys 0.1.4 udev_enumerate_scan_devices().(enumerate) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 {
37 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_enumerate_unrefrust-analyzer cargo libudev-sys 0.1.4 udev_enumerate_unref().(enumerate);
38 return;
39 }
40
41 print_devicesrust-analyzer cargo libudev-sys 0.1.4 print_devices().(
42 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_enumerate_get_udevrust-analyzer cargo libudev-sys 0.1.4 udev_enumerate_get_udev().(enumerate),
43 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_enumerate_get_list_entryrust-analyzer cargo libudev-sys 0.1.4 udev_enumerate_get_list_entry().(enumerate));
44
45 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_enumerate_unrefrust-analyzer cargo libudev-sys 0.1.4 udev_enumerate_unref().(enumerate);
46 }
47
48 unsafe fn print_devicesrust-analyzer cargo libudev-sys 0.1.4 print_devices().(udev: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udevrust-analyzer cargo libudev-sys 0.1.4 udev#, list_entry: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entryrust-analyzer cargo libudev-sys 0.1.4 udev_list_entry#) {
49 if list_entry.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() {
50 return;
51 }
52
53 let syspath = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entry_get_namerust-analyzer cargo libudev-sys 0.1.4 udev_list_entry_get_name().(list_entry);
54 let device = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_new_from_syspathrust-analyzer cargo libudev-sys 0.1.4 udev_device_new_from_syspath().(udev, syspath);
55
56 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().device.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() {
57 print_devicerust-analyzer cargo libudev-sys 0.1.4 print_device().(device);
58 }
59
60 print_devicesrust-analyzer cargo libudev-sys 0.1.4 print_devices().(udev, udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entry_get_nextrust-analyzer cargo libudev-sys 0.1.4 udev_list_entry_get_next().(list_entry));
61 }
62
63 unsafe fn print_devicerust-analyzer cargo libudev-sys 0.1.4 print_device().(device: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_devicerust-analyzer cargo libudev-sys 0.1.4 udev_device#) {
64 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_refrust-analyzer cargo libudev-sys 0.1.4 udev_device_ref().(device);
65
66 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("");
67
68 let initialized = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_is_initializedrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_is_initialized().(device) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().0;
69 let since = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_usec_since_initializedrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_usec_since_initialized().(device);
70
71 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("initialized: {} usec={}", initialized, since);
72 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" devnum: {}", udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_devnumrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_devnum().(device));
73 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" devpath: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_devpathrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_devpath().(device)));
74 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" subsystem: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_subsystemrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_subsystem().(device)));
75 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" devtype: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_devtyperust-analyzer cargo libudev-sys 0.1.4 udev_device_get_devtype().(device)));
76 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" syspath: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_syspathrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_syspath().(device)));
77 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" sysname: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_sysnamerust-analyzer cargo libudev-sys 0.1.4 udev_device_get_sysname().(device)));
78 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" sysnum: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_sysnumrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_sysnum().(device)));
79 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" devnode: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_devnoderust-analyzer cargo libudev-sys 0.1.4 udev_device_get_devnode().(device)));
80 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" driver: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_driverrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_driver().(device)));
81
82 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" properties:");
83 print_device_propertiesrust-analyzer cargo libudev-sys 0.1.4 print_device_properties().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_properties_list_entryrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_properties_list_entry().(device), device);
84
85 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" attributes:");
86 print_device_attributesrust-analyzer cargo libudev-sys 0.1.4 print_device_attributes().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_sysattr_list_entryrust-analyzer cargo libudev-sys 0.1.4 udev_device_get_sysattr_list_entry().(device), device);
87
88 udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_unrefrust-analyzer cargo libudev-sys 0.1.4 udev_device_unref().(device);
89 }
90
91 unsafe fn print_device_propertiesrust-analyzer cargo libudev-sys 0.1.4 print_device_properties().(list_entry: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entryrust-analyzer cargo libudev-sys 0.1.4 udev_list_entry#, device: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_devicerust-analyzer cargo libudev-sys 0.1.4 udev_device#) {
92 if list_entry.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() {
93 return;
94 }
95
96 let propname = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entry_get_namerust-analyzer cargo libudev-sys 0.1.4 udev_list_entry_get_name().(list_entry);
97 let propval = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_property_valuerust-analyzer cargo libudev-sys 0.1.4 udev_device_get_property_value().(device, propname);
98
99 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:>15}: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(propname), unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(propval));
100
101 print_device_propertiesrust-analyzer cargo libudev-sys 0.1.4 print_device_properties().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entry_get_nextrust-analyzer cargo libudev-sys 0.1.4 udev_list_entry_get_next().(list_entry), device);
102 }
103
104 unsafe fn print_device_attributesrust-analyzer cargo libudev-sys 0.1.4 print_device_attributes().(list_entry: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entryrust-analyzer cargo libudev-sys 0.1.4 udev_list_entry#, device: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_devicerust-analyzer cargo libudev-sys 0.1.4 udev_device#) {
105 if list_entry.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() {
106 return;
107 }
108
109 let attrname = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entry_get_namerust-analyzer cargo libudev-sys 0.1.4 udev_list_entry_get_name().(list_entry);
110 let attrval = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_device_get_sysattr_valuerust-analyzer cargo libudev-sys 0.1.4 udev_device_get_sysattr_value().(device, attrname);
111
112 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:>15}: {}", unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(attrname), unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().(attrval));
113
114 print_device_attributesrust-analyzer cargo libudev-sys 0.1.4 print_device_attributes().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entry_get_nextrust-analyzer cargo libudev-sys 0.1.4 udev_list_entry_get_next().(list_entry), device);
115 }
116
117 unsafe fn unwrap_cstrrust-analyzer cargo libudev-sys 0.1.4 unwrap_cstr().<'a>(ptr: *const c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#) -> &'a str {
118 if ptr.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() {
119 ""
120 }
121 else {
122 strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(ptr).to_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_bytes().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().("")
123 }
124 }