| 1 | //! Access to currently active events. |
| 2 | //! |
| 3 | //! The udev daemon processes events asynchronously. All events which do not have |
| 4 | //! interdependencies run in parallel. This exports the current state of the |
| 5 | //! event processing queue, and the current event sequence numbers from the kernel |
| 6 | //! and the udev daemon. |
| 7 | //! |
| 8 | //! From `libudev-queue` documentation. |
| 9 | |
| 10 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 11 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::FromRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/FromRawFd#; |
| 12 | 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/, fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/, syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#}; |
| 13 | |
| 14 | use craterust-analyzer cargo udevrs 0.4.0 crate/::UDEV_ROOT_RUNrust-analyzer cargo udevrs 0.4.0 monitor/UDEV_ROOT_RUN.; |
| 15 | use craterust-analyzer cargo udevrs 0.4.0 crate/::{Errorrust-analyzer cargo udevrs 0.4.0 error/Error#, Resultrust-analyzer cargo udevrs 0.4.0 error/Result#, Udevrust-analyzer cargo udevrs 0.4.0 context/Udev#, UdevEntryListrust-analyzer cargo udevrs 0.4.0 list/UdevEntryList#, UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#}; |
| 16 | |
| 17 | /// Represents the current event queue in the udev daemon. |
| 18 | #[repr(C)] |
| 19 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 20 | pub struct UdevQueuerust-analyzer cargo udevrs 0.4.0 queue/UdevQueue# { |
| 21 | udevrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#udev.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Udevrust-analyzer cargo udevrs 0.4.0 context/Udev#>, |
| 22 | queue_listrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#queue_list.: UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#, |
| 23 | fdrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#fd.: i32, |
| 24 | } |
| 25 | |
| 26 | impl UdevQueuerust-analyzer cargo udevrs 0.4.0 queue/UdevQueue# { |
| 27 | /// Creates a new [UdevQueue]. |
| 28 | pub fn newrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]new().(udev: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Udevrust-analyzer cargo udevrs 0.4.0 context/Udev#>) -> Selfrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue] { |
| 29 | let udev_arc = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&udev); |
| 30 | Selfrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue] { |
| 31 | udevrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#udev., |
| 32 | queue_listrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#queue_list.: UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#::newrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]new().(udev_arc), |
| 33 | fdrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#fd.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1, |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /// Creates a new [UdevQueue] from the provided parameters. |
| 38 | pub fn createrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]create().<Q: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<UdevEntryListrust-analyzer cargo udevrs 0.4.0 list/UdevEntryList#>>(udev: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Udevrust-analyzer cargo udevrs 0.4.0 context/Udev#>, queue_list: Q, fd: i32) -> Selfrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue] { |
| 39 | let udev_arc = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&udev); |
| 40 | Selfrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue] { |
| 41 | udevrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#udev., |
| 42 | queue_listrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#queue_list.: UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#::createrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]create().(udev_arc, queue_list.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()), |
| 43 | fdrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#fd., |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /// Gets a reference to the [Udev] context. |
| 48 | pub const fn udevrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]udev().(&self) -> &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Udevrust-analyzer cargo udevrs 0.4.0 context/Udev#> { |
| 49 | &self.udevrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#udev. |
| 50 | } |
| 51 | |
| 52 | /// Gets a reference to the queue list [UdevList]. |
| 53 | pub const fn queue_listrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]queue_list().(&self) -> &UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList# { |
| 54 | &self.queue_listrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#queue_list. |
| 55 | } |
| 56 | |
| 57 | /// Gets a mutable reference to the queue list [UdevList]. |
| 58 | pub fn queue_list_mutrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]queue_list_mut().(&mut self) -> &mut UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList# { |
| 59 | &mut self.queue_listrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#queue_list. |
| 60 | } |
| 61 | |
| 62 | /// Sets the queue list [UdevEntryList]. |
| 63 | pub fn set_queue_listrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]set_queue_list().<Q: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<UdevEntryListrust-analyzer cargo udevrs 0.4.0 list/UdevEntryList#>>(&mut self, queue_list: Q) { |
| 64 | self.queue_listrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#queue_list..set_listrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]set_list().(queue_list); |
| 65 | } |
| 66 | |
| 67 | /// Builder function that sets the queue list [UdevEntryList]. |
| 68 | pub fn with_queue_listrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]with_queue_list().<Q: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<UdevEntryListrust-analyzer cargo udevrs 0.4.0 list/UdevEntryList#>>(mut self, queue_list: Q) -> Selfrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue] { |
| 69 | self.set_queue_listrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]set_queue_list().(queue_list); |
| 70 | self |
| 71 | } |
| 72 | |
| 73 | /// Gets the length of the [UdevQueue]. |
| 74 | pub fn lenrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]len().(&self) -> usize { |
| 75 | self.queue_listrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#queue_list..lenrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]len().() |
| 76 | } |
| 77 | |
| 78 | /// Gets whether the [UdevQueue] is empty. |
| 79 | pub fn is_emptyrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]is_empty().(&self) -> bool { |
| 80 | self.queue_listrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#queue_list..is_emptyrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]is_empty().() |
| 81 | } |
| 82 | |
| 83 | /// Gets the [UdevQueue] file descriptor. |
| 84 | pub const fn fdrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]fd().(&self) -> i32 { |
| 85 | self.fdrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#fd. |
| 86 | } |
| 87 | |
| 88 | /// Sets the [UdevQueue] file descriptor. |
| 89 | pub fn set_fdrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]set_fd().(&mut self, val: i32) { |
| 90 | self.fdrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#fd. = val; |
| 91 | } |
| 92 | |
| 93 | /// Builder function that sets the [UdevQueue] file descriptor. |
| 94 | pub fn with_fdrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]with_fd().(mut self, val: i32) -> Selfrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue] { |
| 95 | self.set_fdrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]set_fd().(val); |
| 96 | self |
| 97 | } |
| 98 | |
| 99 | /// Gets a file descriptor to watch for a queue to become empty. |
| 100 | pub fn get_fdrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]get_fd().(&mut self) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<i32> { |
| 101 | if self.fdrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#fd. 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 { |
| 102 | // SAFETY: the argument is valid, and the return value is checked before use. |
| 103 | let fd = unsafe { libcrust-analyzer cargo libc 0.2.169 crate/::inotify_init1rust-analyzer cargo libc 0.2.169 inotify_init1().(libcrust-analyzer cargo libc 0.2.169 crate/::IN_CLOEXECrust-analyzer cargo libc 0.2.169 unix/linux_like/linux/IN_CLOEXEC.) }; |
| 104 | if fd 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 { |
| 105 | let errno = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().(); |
| 106 | let err_msg = |
| 107 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unable to init inotify monitor, error: {fd}, errno: {errno}"); |
| 108 | logrust-analyzer cargo log 0.4.25 crate/::errorrust-analyzer cargo log 0.4.25 macros/error!!("{err_msg}"); |
| 109 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::UdevQueuerust-analyzer cargo udevrs 0.4.0 error/Error#UdevQueue#(err_msg)) |
| 110 | } else { |
| 111 | let udev_path = ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{UDEV_ROOT_RUN}/udev"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 112 | // SAFETY: arguments are valid, and pointers reference valid memory. |
| 113 | let r = unsafe { |
| 114 | libcrust-analyzer cargo libc 0.2.169 crate/::inotify_add_watchrust-analyzer cargo libc 0.2.169 inotify_add_watch().(fd, udev_path.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().() as *const _, libcrust-analyzer cargo libc 0.2.169 crate/::IN_DELETErust-analyzer cargo libc 0.2.169 unix/linux_like/linux/IN_DELETE.) |
| 115 | }; |
| 116 | if r 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 { |
| 117 | let errno = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().(); |
| 118 | let err_msg = |
| 119 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unable to add inotify watch event, error: {r}, errno: {errno}"); |
| 120 | logrust-analyzer cargo log 0.4.25 crate/::errorrust-analyzer cargo log 0.4.25 macros/error!!("{err_msg}"); |
| 121 | // SAFETY: argument is valid |
| 122 | unsafe { libcrust-analyzer cargo libc 0.2.169 crate/::closerust-analyzer cargo libc 0.2.169 close().(fd) }; |
| 123 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::UdevQueuerust-analyzer cargo udevrs 0.4.0 error/Error#UdevQueue#(err_msg)) |
| 124 | } else { |
| 125 | self.fdrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#fd. = fd; |
| 126 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(fd) |
| 127 | } |
| 128 | } |
| 129 | } else { |
| 130 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.fdrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#fd.) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /// Clears the watched file descriptor for queue changes. |
| 135 | /// |
| 136 | /// # Safety |
| 137 | /// |
| 138 | /// Users must ensure that every [UdevQueue] has a unique file descriptor, if the descriptor is |
| 139 | /// non-negative. |
| 140 | /// |
| 141 | /// Returns: `Ok(())` on success, `Err(Error)` otherwise. |
| 142 | pub fn flushrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]flush().(&mut self) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<()> { |
| 143 | let fd = self.fdrust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#fd.; |
| 144 | if fd 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 { |
| 145 | let err = libcrust-analyzer cargo libc 0.2.169 crate/::EINVALrust-analyzer cargo libc 0.2.169 unix/linux_like/linux/EINVAL.; |
| 146 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::UdevQueuerust-analyzer cargo udevrs 0.4.0 error/Error#UdevQueue#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 147 | "invalid file descriptor, fd: {fd}, error: {err}" |
| 148 | ))) |
| 149 | } else { |
| 150 | // SAFETY: argument is valid, and only one valid mutable reference to this UdevQueue |
| 151 | // can be held without further `unsafe` code. |
| 152 | // |
| 153 | // Users must ensure that every UdevQueue has a unique file descriptor. |
| 154 | let mut file = unsafe { fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::from_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][FromRawFd]from_raw_fd().(fd) }; |
| 155 | file.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Write]flush().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| { |
| 156 | let errno = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().(); |
| 157 | let err_msg = |
| 158 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unable to flush queue file descriptor, error: {err}, errno: {errno}"); |
| 159 | logrust-analyzer cargo log 0.4.25 crate/::errorrust-analyzer cargo log 0.4.25 macros/error!!("{err_msg}"); |
| 160 | Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::UdevQueuerust-analyzer cargo udevrs 0.4.0 error/Error#UdevQueue#(err_msg) |
| 161 | }) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /// Checks if [Udev] is active on the system. |
| 166 | pub fn udev_is_activerust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]udev_is_active().(&self) -> bool { |
| 167 | fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]new().() |
| 168 | .readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]read().(true) |
| 169 | .openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{UDEV_ROOT_RUN}/udev/control")) |
| 170 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() |
| 171 | } |
| 172 | |
| 173 | /// Gets whether [UdevQueue] is currently processing any events. |
| 174 | pub fn queue_is_emptyrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]queue_is_empty().(&self) -> bool { |
| 175 | fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]new().() |
| 176 | .readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]read().(true) |
| 177 | .openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{UDEV_ROOT_RUN}/udev/queue")) |
| 178 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | #[cfg(test)] |
| 183 | mod testsrust-analyzer cargo udevrs 0.4.0 queue/tests/ { |
| 184 | use superrust-analyzer cargo udevrs 0.4.0 queue/::*; |
| 185 | use craterust-analyzer cargo udevrs 0.4.0 crate/::UdevEntryrust-analyzer cargo udevrs 0.4.0 list/UdevEntry#; |
| 186 | |
| 187 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 188 | fn test_udev_queuerust-analyzer cargo udevrs 0.4.0 queue/tests/test_udev_queue().() { |
| 189 | let udev = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(Udevrust-analyzer cargo udevrs 0.4.0 context/Udev#::newrust-analyzer cargo udevrs 0.4.0 context/impl#[Udev]new().()); |
| 190 | let mut null_queue = UdevQueuerust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#::newrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]new().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&udev)); |
| 191 | |
| 192 | let exp_list = [UdevEntryrust-analyzer cargo udevrs 0.4.0 list/UdevEntry#::newrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevEntry]new().().with_namerust-analyzer cargo udevrs 0.4.0 list/impl#[UdevEntry]with_name().("test_list_entry")]; |
| 193 | let exp_queue = UdevQueuerust-analyzer cargo udevrs 0.4.0 queue/UdevQueue#::createrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]create().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&udev), exp_list.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][Clone]clone().(), -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1); |
| 194 | |
| 195 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(null_queue.queue_listrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]queue_list().().is_emptyrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]is_empty().()); |
| 196 | |
| 197 | for (entry, exp_entry) in exp_queue.queue_listrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]queue_list().().iterrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(exp_list.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) { |
| 198 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(entry, exp_entry); |
| 199 | } |
| 200 | |
| 201 | null_queue.set_queue_listrust-analyzer cargo udevrs 0.4.0 queue/impl#[UdevQueue]set_queue_list().(exp_list); |
| 202 | |
| 203 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(null_queue, exp_queue); |
| 204 | } |
| 205 | } |