| 1 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::{Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#, RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#}; |
| 2 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#; |
| 3 |
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/; |
| 4 |
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/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/io/::AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#; |
| 5 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/::Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#; |
| 6 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::{AtomicBoolrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicBool#, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#}; |
| 7 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::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#; |
| 8 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::{Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#}; |
| 9 |
|
| 10 |
use slotmaprust-analyzer cargo slotmap 1.0.6 crate/::SlotMaprust-analyzer cargo slotmap 1.0.6 basic/SlotMap#; |
| 11 |
|
| 12 |
use craterust-analyzer cargo calloop 0.10.5 crate/::sourcesrust-analyzer cargo calloop 0.10.5 sources/::{Dispatcherrust-analyzer cargo calloop 0.10.5 sources/Dispatcher#, EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource#, Idlerust-analyzer cargo calloop 0.10.5 sources/Idle#, IdleDispatcherrust-analyzer cargo calloop 0.10.5 sources/IdleDispatcher#}; |
| 13 |
use craterust-analyzer cargo calloop 0.10.5 crate/::{EventDispatcherrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#, InsertErrorrust-analyzer cargo calloop 0.10.5 error/InsertError#, Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#, TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#}; |
| 14 |
|
| 15 |
type IdleCallbackrust-analyzer cargo calloop 0.10.5 loop_logic/IdleCallback#<'i, Data> = Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<dyn IdleDispatcherrust-analyzer cargo calloop 0.10.5 sources/IdleDispatcher#<Data> + 'i>>; |
| 16 |
|
| 17 |
slotmaprust-analyzer cargo slotmap 1.0.6 crate/::new_key_typerust-analyzer cargo slotmap 1.0.6 new_key_type!! { |
| 18 |
pub(craterust-analyzer cargo calloop 0.10.5 crate/) struct CalloopKeyrust-analyzer cargo calloop 0.10.5 loop_logic/CalloopKey#; |
| 19 |
} |
| 20 |
|
| 21 |
/// A token representing a registration in the [`EventLoop`]. |
| 22 |
/// |
| 23 |
/// This token is given to you by the [`EventLoop`] when an [`EventSource`] is inserted or |
| 24 |
/// a [`Dispatcher`] is registered. You can use it to [disable](LoopHandle#method.disable), |
| 25 |
/// [enable](LoopHandle#method.enable), [update`](LoopHandle#method.update), |
| 26 |
/// [remove](LoopHandle#method.remove) or [kill](LoopHandle#method.kill) it. |
| 27 |
#[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 28 |
pub struct RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken# { |
| 29 |
keyrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#key.: CalloopKeyrust-analyzer cargo calloop 0.10.5 loop_logic/CalloopKey#, |
| 30 |
} |
| 31 |
|
| 32 |
pub(craterust-analyzer cargo calloop 0.10.5 crate/) struct LoopInnerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#<'l, Data> { |
| 33 |
pub(craterust-analyzer cargo calloop 0.10.5 crate/) pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#>, |
| 34 |
pub(craterust-analyzer cargo calloop 0.10.5 crate/) sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<SlotMaprust-analyzer cargo slotmap 1.0.6 basic/SlotMap#<CalloopKeyrust-analyzer cargo calloop 0.10.5 loop_logic/CalloopKey#, Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<dyn EventDispatcherrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#<Data> + 'l>>>, |
| 35 |
idlesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#idles.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<IdleCallbackrust-analyzer cargo calloop 0.10.5 loop_logic/IdleCallback#<'l, Data>>>, |
| 36 |
pending_actionrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#pending_action.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#<PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#>, |
| 37 |
} |
| 38 |
|
| 39 |
/// An handle to an event loop |
| 40 |
/// |
| 41 |
/// This handle allows you to insert new sources and idles in this event loop, |
| 42 |
/// it can be cloned, and it is possible to insert new sources from within a source |
| 43 |
/// callback. |
| 44 |
pub struct LoopHandlerust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#<'l, Data> { |
| 45 |
innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner.: Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<LoopInnerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#<'l, Data>>, |
| 46 |
} |
| 47 |
|
| 48 |
impl<'l, Data> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for LoopHandlerust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#<'l, Data> { |
| 49 |
#[cfg_attr(coverage, no_coverage)] |
| 50 |
fn fmtrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 51 |
f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("LoopHandle { ... }") |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
impl<'l, Data> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for LoopHandlerust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#<'l, Data> { |
| 56 |
#[cfg_attr(coverage, no_coverage)] |
| 57 |
fn clonerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`][Clone]clone().(&self) -> Selfrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`][Clone] { |
| 58 |
LoopHandlerust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle# { |
| 59 |
innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner.: self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`][Clone]clone().(), |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
impl<'l, Data> LoopHandlerust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#<'l, Data> { |
| 65 |
/// Inserts a new event source in the loop. |
| 66 |
/// |
| 67 |
/// The provided callback will be called during the dispatching cycles whenever the |
| 68 |
/// associated source generates events, see `EventLoop::dispatch(..)` for details. |
| 69 |
/// |
| 70 |
/// This function takes ownership of the event source. Use `register_dispatcher` |
| 71 |
/// if you need access to the event source after this call. |
| 72 |
pub fn insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().<S, F>( |
| 73 |
&self, |
| 74 |
source: S, |
| 75 |
callback: F, |
| 76 |
) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#, InsertErrorrust-analyzer cargo calloop 0.10.5 error/InsertError#<S>> |
| 77 |
where |
| 78 |
S: EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource# + 'l, |
| 79 |
F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(S::Eventrust-analyzer cargo calloop 0.10.5 sources/EventSource#Event#, &mut S::Metadatarust-analyzer cargo calloop 0.10.5 sources/EventSource#Metadata#, &mut Data) -> S::Retrust-analyzer cargo calloop 0.10.5 sources/EventSource#Ret# + 'l, |
| 80 |
{ |
| 81 |
let dispatcher = Dispatcherrust-analyzer cargo calloop 0.10.5 sources/Dispatcher#::newrust-analyzer cargo calloop 0.10.5 sources/impl#[`Dispatcher<'a, S, Data>`]new().(source, callback); |
| 82 |
self.register_dispatcherrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]register_dispatcher().(dispatcher.clonerust-analyzer cargo calloop 0.10.5 sources/impl#[`Dispatcher<'a, S, Data>`][Clone]clone().()) |
| 83 |
.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|error| InsertErrorrust-analyzer cargo calloop 0.10.5 error/InsertError# { |
| 84 |
errorrust-analyzer cargo calloop 0.10.5 error/InsertError#error., |
| 85 |
insertedrust-analyzer cargo calloop 0.10.5 error/InsertError#inserted.: dispatcher.into_source_innerrust-analyzer cargo calloop 0.10.5 sources/impl#[`Dispatcher<'a, S, Data>`]into_source_inner().(), |
| 86 |
}) |
| 87 |
} |
| 88 |
|
| 89 |
/// Registers a `Dispatcher` in the loop. |
| 90 |
/// |
| 91 |
/// Use this function if you need access to the event source after its insertion in the loop. |
| 92 |
/// |
| 93 |
/// See also `insert_source`. |
| 94 |
pub fn register_dispatcherrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]register_dispatcher().<S>( |
| 95 |
&self, |
| 96 |
dispatcher: Dispatcherrust-analyzer cargo calloop 0.10.5 sources/Dispatcher#<'l, S, Data>, |
| 97 |
) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#> |
| 98 |
where |
| 99 |
S: EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource# + 'l, |
| 100 |
{ |
| 101 |
let mut sources = self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().(); |
| 102 |
let mut poll = self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().(); |
| 103 |
|
| 104 |
let key = sources.insertrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]insert().(dispatcher.clone_as_event_dispatcherrust-analyzer cargo calloop 0.10.5 sources/impl#[`Dispatcher<'a, S, Data>`]clone_as_event_dispatcher().()); |
| 105 |
let ret = sources |
| 106 |
.getrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]get().(key) |
| 107 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 108 |
.registerrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#register().(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefMut<'_, T>`][DerefMut]deref_mut().poll, &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#::newrust-analyzer cargo calloop 0.10.5 sys/impl#[TokenFactory]new().(key)); |
| 109 |
|
| 110 |
if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = ret { |
| 111 |
sources.removerust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]remove().(key).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Source was just inserted?!"); |
| 112 |
return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error); |
| 113 |
} |
| 114 |
|
| 115 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken# { keyrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#key. }) |
| 116 |
} |
| 117 |
|
| 118 |
/// Inserts an idle callback. |
| 119 |
/// |
| 120 |
/// This callback will be called during a dispatching cycle when the event loop has |
| 121 |
/// finished processing all pending events from the sources and becomes idle. |
| 122 |
pub fn insert_idlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_idle().<'i, F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&mut Data) + 'l + 'i>(&self, callback: F) -> Idlerust-analyzer cargo calloop 0.10.5 sources/Idle#<'i> { |
| 123 |
let mut opt_cb = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(callback); |
| 124 |
let callback = Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]new().(RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(move |data: &mut Data| { |
| 125 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cb) = opt_cb.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() { |
| 126 |
cb(data); |
| 127 |
} |
| 128 |
}))); |
| 129 |
self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..idlesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#idles..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().().pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(callback.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`][Clone]clone().()); |
| 130 |
Idlerust-analyzer cargo calloop 0.10.5 sources/Idle# { callbackrust-analyzer cargo calloop 0.10.5 sources/Idle#callback. } |
| 131 |
} |
| 132 |
|
| 133 |
/// Enables this previously disabled event source. |
| 134 |
/// |
| 135 |
/// This previously disabled source will start generating events again. |
| 136 |
/// |
| 137 |
/// **Note:** this cannot be done from within the source callback. |
| 138 |
pub fn enablerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]enable().(&self, token: &RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 139 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(source) = self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().getrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]get().(token.keyrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#key.) { |
| 140 |
source.registerrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#register().( |
| 141 |
&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefMut<'_, T>`][DerefMut]deref_mut().self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().(), |
| 142 |
&mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#::newrust-analyzer cargo calloop 0.10.5 sys/impl#[TokenFactory]new().(token.keyrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#key.), |
| 143 |
)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 144 |
} |
| 145 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 146 |
} |
| 147 |
|
| 148 |
/// Makes this source update its registration. |
| 149 |
/// |
| 150 |
/// If after accessing the source you changed its parameters in a way that requires |
| 151 |
/// updating its registration. |
| 152 |
pub fn updaterust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]update().(&self, token: &RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 153 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(source) = self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().getrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]get().(token.keyrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#key.) { |
| 154 |
if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().source.reregisterrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#reregister().( |
| 155 |
&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefMut<'_, T>`][DerefMut]deref_mut().self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().(), |
| 156 |
&mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#::newrust-analyzer cargo calloop 0.10.5 sys/impl#[TokenFactory]new().(token.keyrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#key.), |
| 157 |
)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 158 |
// we are in a callback, store for later processing |
| 159 |
self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pending_actionrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#pending_action..setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]set().(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Reregisterrust-analyzer cargo calloop 0.10.5 sources/PostAction#Reregister#); |
| 160 |
} |
| 161 |
} |
| 162 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 163 |
} |
| 164 |
|
| 165 |
/// Disables this event source. |
| 166 |
/// |
| 167 |
/// The source remains in the event loop, but it'll no longer generate events |
| 168 |
pub fn disablerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]disable().(&self, token: &RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 169 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(source) = self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().getrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]get().(token.keyrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#key.) { |
| 170 |
if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().source.unregisterrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#unregister().(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefMut<'_, T>`][DerefMut]deref_mut().self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 171 |
// we are in a callback, store for later processing |
| 172 |
self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pending_actionrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#pending_action..setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]set().(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Disablerust-analyzer cargo calloop 0.10.5 sources/PostAction#Disable#); |
| 173 |
} |
| 174 |
} |
| 175 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 176 |
} |
| 177 |
|
| 178 |
/// Removes this source from the event loop. |
| 179 |
pub fn removerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]remove().(&self, token: RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#) { |
| 180 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(source) = self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().().removerust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]remove().(token.keyrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#key.) { |
| 181 |
if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = source.unregisterrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#unregister().(&mut self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().()) { |
| 182 |
logrust-analyzer cargo log 0.4.17 crate/::warnrust-analyzer cargo log 0.4.17 macros/warn!!( |
| 183 |
"[calloop] Failed to unregister source from the polling system: {:?}", |
| 184 |
e |
| 185 |
); |
| 186 |
} |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
/// Wrap an IO object into an async adapter |
| 191 |
/// |
| 192 |
/// This adapter turns the IO object into an async-aware one that can be used in futures. |
| 193 |
/// The readiness of these futures will be driven by the event loop. |
| 194 |
/// |
| 195 |
/// The produced futures can be polled in any executor, and notably the one provided by |
| 196 |
/// calloop. |
| 197 |
pub fn adapt_iorust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]adapt_io().<F: AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#>(&self, fd: F) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<craterust-analyzer cargo calloop 0.10.5 crate/::iorust-analyzer cargo calloop 0.10.5 io/::Asyncrust-analyzer cargo calloop 0.10.5 io/Async#<'l, F>> { |
| 198 |
craterust-analyzer cargo calloop 0.10.5 crate/::iorust-analyzer cargo calloop 0.10.5 io/::Asyncrust-analyzer cargo calloop 0.10.5 io/Async#::newrust-analyzer cargo calloop 0.10.5 io/impl#[`Async<'l, F>`]new().(self.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`][Clone]clone().(), fd) |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
/// An event loop |
| 203 |
/// |
| 204 |
/// This loop can host several event sources, that can be dynamically added or removed. |
| 205 |
pub struct EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#<'l, Data> { |
| 206 |
handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle.: LoopHandlerust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#<'l, Data>, |
| 207 |
stop_signalrust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#stop_signal.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<AtomicBoolrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicBool#>, |
| 208 |
pingrust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#ping.: craterust-analyzer cargo calloop 0.10.5 crate/::sourcesrust-analyzer cargo calloop 0.10.5 sources/::pingrust-analyzer cargo calloop 0.10.5 sources/ping/::Pingrust-analyzer cargo calloop 0.10.5 sources/ping/Ping#, |
| 209 |
} |
| 210 |
|
| 211 |
impl<'l, Data> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#<'l, Data> { |
| 212 |
#[cfg_attr(coverage, no_coverage)] |
| 213 |
fn fmtrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 214 |
f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("EventLoop { ... }") |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
impl<'l, Data> EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#<'l, Data> { |
| 219 |
/// Create a new event loop |
| 220 |
/// |
| 221 |
/// Fails if the initialization of the polling system failed. |
| 222 |
pub fn try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().() -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<Selfrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]> { |
| 223 |
Selfrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]::inner_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]inner_new().(false) |
| 224 |
} |
| 225 |
|
| 226 |
/// Create a new event loop in high precision mode |
| 227 |
/// |
| 228 |
/// On some platforms it requires to setup more resources to enable high-precision |
| 229 |
/// (sub millisecond) capabilities, so you should use this constructor if you need |
| 230 |
/// this kind of precision. |
| 231 |
/// |
| 232 |
/// Fails if the initialization of the polling system failed. |
| 233 |
pub fn try_new_high_precisionrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new_high_precision().() -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<Selfrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]> { |
| 234 |
Selfrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]::inner_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]inner_new().(true) |
| 235 |
} |
| 236 |
|
| 237 |
fn inner_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]inner_new().(high_precision: bool) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<Selfrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]> { |
| 238 |
let poll = Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#::newrust-analyzer cargo calloop 0.10.5 sys/impl#[Poll]new().(high_precision)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 239 |
let handle = LoopHandlerust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle# { |
| 240 |
innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner.: Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]new().(LoopInnerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner# { |
| 241 |
pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(poll), |
| 242 |
sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(SlotMaprust-analyzer cargo slotmap 1.0.6 basic/SlotMap#::with_keyrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]with_key().()), |
| 243 |
idlesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#idles.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()), |
| 244 |
pending_actionrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#pending_action.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue#), |
| 245 |
}), |
| 246 |
}; |
| 247 |
let (ping, ping_source) = craterust-analyzer cargo calloop 0.10.5 crate/::sourcesrust-analyzer cargo calloop 0.10.5 sources/::pingrust-analyzer cargo calloop 0.10.5 sources/ping/::make_pingrust-analyzer cargo calloop 0.10.5 sources/ping/make_ping().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 248 |
handle.insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().(ping_source, |_, _, _| {})?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 249 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop# { |
| 250 |
handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle., |
| 251 |
stop_signalrust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#stop_signal.: 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().(AtomicBoolrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicBool#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicBool]new().(false)), |
| 252 |
pingrust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#ping., |
| 253 |
}) |
| 254 |
} |
| 255 |
|
| 256 |
/// Retrieve a loop handle |
| 257 |
pub fn handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().(&self) -> LoopHandlerust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#<'l, Data> { |
| 258 |
self.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle..clonerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`][Clone]clone().() |
| 259 |
} |
| 260 |
|
| 261 |
fn dispatch_eventsrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch_events().( |
| 262 |
&mut self, |
| 263 |
mut timeout: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#>, |
| 264 |
data: &mut Data, |
| 265 |
) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 266 |
let now = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().(); |
| 267 |
let events = { |
| 268 |
let mut poll = self.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle..innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().(); |
| 269 |
loop { |
| 270 |
let result = poll.pollrust-analyzer cargo calloop 0.10.5 sys/impl#[Poll]poll().(timeout); |
| 271 |
|
| 272 |
match result { |
| 273 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(events) => break events, |
| 274 |
Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(craterust-analyzer cargo calloop 0.10.5 crate/::Errorrust-analyzer cargo calloop 0.10.5 error/Error#::IoErrorrust-analyzer cargo calloop 0.10.5 error/Error#IoError#(err)) if err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Interruptedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Interrupted# => { |
| 275 |
// Interrupted by a signal. Update timeout and retry. |
| 276 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(to) = timeout { |
| 277 |
let elapsed = now.elapsedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]elapsed().(); |
| 278 |
if elapsed rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge().to { |
| 279 |
return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 280 |
} else { |
| 281 |
timeout = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(to rust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration][`Sub<Self>`]sub().elapsed); |
| 282 |
} |
| 283 |
} |
| 284 |
} |
| 285 |
Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err), |
| 286 |
}; |
| 287 |
} |
| 288 |
}; |
| 289 |
|
| 290 |
for event in events { |
| 291 |
let opt_disp = self |
| 292 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle. |
| 293 |
.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner. |
| 294 |
.sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources. |
| 295 |
.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().() |
| 296 |
.getrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]get().(event.tokenrust-analyzer cargo calloop 0.10.5 sys/PollEvent#token..keyrust-analyzer cargo calloop 0.10.5 sys/Token#key.) |
| 297 |
.clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().(); |
| 298 |
|
| 299 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(disp) = opt_disp { |
| 300 |
let mut ret = disp.process_eventsrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#process_events().(event.readinessrust-analyzer cargo calloop 0.10.5 sys/PollEvent#readiness., event.tokenrust-analyzer cargo calloop 0.10.5 sys/PollEvent#token., data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 301 |
|
| 302 |
// if the returned PostAction is Continue, it may be overwritten by an user-specified pending action |
| 303 |
let pending_action = self |
| 304 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle. |
| 305 |
.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner. |
| 306 |
.pending_actionrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#pending_action. |
| 307 |
.replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]replace().(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue#); |
| 308 |
if let PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue# = ret { |
| 309 |
ret = pending_action; |
| 310 |
} |
| 311 |
|
| 312 |
match ret { |
| 313 |
PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Reregisterrust-analyzer cargo calloop 0.10.5 sources/PostAction#Reregister# => { |
| 314 |
disp.reregisterrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#reregister().( |
| 315 |
&mut self.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle..innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().(), |
| 316 |
&mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#::newrust-analyzer cargo calloop 0.10.5 sys/impl#[TokenFactory]new().(event.tokenrust-analyzer cargo calloop 0.10.5 sys/PollEvent#token..keyrust-analyzer cargo calloop 0.10.5 sys/Token#key.), |
| 317 |
)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 318 |
} |
| 319 |
PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Disablerust-analyzer cargo calloop 0.10.5 sources/PostAction#Disable# => { |
| 320 |
disp.unregisterrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#unregister().(&mut self.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle..innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 321 |
} |
| 322 |
PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Removerust-analyzer cargo calloop 0.10.5 sources/PostAction#Remove# => { |
| 323 |
// delete the source from the list, it'll be cleaned up with the if just below |
| 324 |
self.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle. |
| 325 |
.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner. |
| 326 |
.sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources. |
| 327 |
.borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().() |
| 328 |
.removerust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]remove().(event.tokenrust-analyzer cargo calloop 0.10.5 sys/PollEvent#token..keyrust-analyzer cargo calloop 0.10.5 sys/Token#key.); |
| 329 |
} |
| 330 |
PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue# => {} |
| 331 |
} |
| 332 |
|
| 333 |
if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self |
| 334 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle. |
| 335 |
.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner. |
| 336 |
.sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources. |
| 337 |
.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().() |
| 338 |
.contains_keyrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]contains_key().(event.tokenrust-analyzer cargo calloop 0.10.5 sys/PollEvent#token..keyrust-analyzer cargo calloop 0.10.5 sys/Token#key.) |
| 339 |
{ |
| 340 |
// the source has been removed from within its callback, unregister it |
| 341 |
let mut poll = self.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle..innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..pollrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#poll..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().(); |
| 342 |
if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = disp.unregisterrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#unregister().(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefMut<'_, T>`][DerefMut]deref_mut().poll) { |
| 343 |
logrust-analyzer cargo log 0.4.17 crate/::warnrust-analyzer cargo log 0.4.17 macros/warn!!( |
| 344 |
"[calloop] Failed to unregister source from the polling system: {:?}", |
| 345 |
e |
| 346 |
); |
| 347 |
} |
| 348 |
} |
| 349 |
} else { |
| 350 |
logrust-analyzer cargo log 0.4.17 crate/::warnrust-analyzer cargo log 0.4.17 macros/warn!!( |
| 351 |
"[calloop] Received an event for non-existence source: {:?}", |
| 352 |
event.tokenrust-analyzer cargo calloop 0.10.5 sys/PollEvent#token..keyrust-analyzer cargo calloop 0.10.5 sys/Token#key. |
| 353 |
); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 358 |
} |
| 359 |
|
| 360 |
fn dispatch_idlesrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch_idles().(&mut self, data: &mut Data) { |
| 361 |
let idles = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefMut<'_, T>`][DerefMut]deref_mut().self.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle..innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner..idlesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#idles..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().()); |
| 362 |
for idle in idles { |
| 363 |
idle.borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().().dispatchrust-analyzer cargo calloop 0.10.5 sources/IdleDispatcher#dispatch().(data); |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
fn invoke_pre_runrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]invoke_pre_run().(&self, data: &mut Data) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 368 |
let sources = self |
| 369 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle. |
| 370 |
.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner. |
| 371 |
.sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources. |
| 372 |
.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().() |
| 373 |
.valuesrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]values().() |
| 374 |
.clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().() |
| 375 |
.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 376 |
|
| 377 |
for source in sources { |
| 378 |
source.pre_runrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#pre_run().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 379 |
} |
| 380 |
|
| 381 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 382 |
} |
| 383 |
|
| 384 |
fn invoke_post_runrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]invoke_post_run().(&self, data: &mut Data) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 385 |
let sources = self |
| 386 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#handle. |
| 387 |
.innerrust-analyzer cargo calloop 0.10.5 loop_logic/LoopHandle#inner. |
| 388 |
.sourcesrust-analyzer cargo calloop 0.10.5 loop_logic/LoopInner#sources. |
| 389 |
.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().() |
| 390 |
.valuesrust-analyzer cargo slotmap 1.0.6 basic/impl#[`SlotMap<K, V>`]values().() |
| 391 |
.clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().() |
| 392 |
.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 393 |
|
| 394 |
for source in sources { |
| 395 |
source.post_runrust-analyzer cargo calloop 0.10.5 sources/EventDispatcher#post_run().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 396 |
} |
| 397 |
|
| 398 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 399 |
} |
| 400 |
|
| 401 |
/// Dispatch pending events to their callbacks |
| 402 |
/// |
| 403 |
/// If some sources have events available, their callbacks will be immediatly called. |
| 404 |
/// Otherwise this will wait until an event is receive or the provided `timeout` |
| 405 |
/// is reached. If `timeout` is `None`, it will wait without a duration limit. |
| 406 |
/// |
| 407 |
/// Once pending events have been processed or the timeout is reached, all pending |
| 408 |
/// idle callbacks will be fired before this method returns. |
| 409 |
pub fn dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().<D: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#>>>( |
| 410 |
&mut self, |
| 411 |
timeout: D, |
| 412 |
data: &mut Data, |
| 413 |
) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 414 |
self.invoke_pre_runrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]invoke_pre_run().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 415 |
self.dispatch_eventsrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch_events().(timeout.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 416 |
self.dispatch_idlesrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch_idles().(data); |
| 417 |
self.invoke_post_runrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]invoke_post_run().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 418 |
|
| 419 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 420 |
} |
| 421 |
|
| 422 |
/// Get a signal to stop this event loop from running |
| 423 |
/// |
| 424 |
/// To be used in conjunction with the `run()` method. |
| 425 |
pub fn get_signalrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]get_signal().(&self) -> LoopSignalrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal# { |
| 426 |
LoopSignalrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal# { |
| 427 |
signalrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal#signal.: self.stop_signalrust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#stop_signal..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), |
| 428 |
pingrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal#ping.: self.pingrust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#ping..clonerust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping][Clone]clone().(), |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
/// Run this event loop |
| 433 |
/// |
| 434 |
/// This will repeatedly try to dispatch events (see the `dispatch()` method) on |
| 435 |
/// this event loop, waiting at most `timeout` every time. |
| 436 |
/// |
| 437 |
/// Between each dispatch wait, your provided callback will be called. |
| 438 |
/// |
| 439 |
/// You can use the `get_signal()` method to retrieve a way to stop or wakeup |
| 440 |
/// the event loop from anywhere. |
| 441 |
pub fn runrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]run().<F, D: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#>>>( |
| 442 |
&mut self, |
| 443 |
timeout: D, |
| 444 |
data: &mut Data, |
| 445 |
mut cb: F, |
| 446 |
) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> |
| 447 |
where |
| 448 |
F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut Data), |
| 449 |
{ |
| 450 |
let timeout = timeout.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 451 |
self.stop_signalrust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#stop_signal..storerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicBool]store().(false, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Releaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Release#); |
| 452 |
self.invoke_pre_runrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]invoke_pre_run().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 453 |
while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.stop_signalrust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#stop_signal..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicBool]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) { |
| 454 |
self.dispatch_eventsrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch_events().(timeout, data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 455 |
self.dispatch_idlesrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch_idles().(data); |
| 456 |
cb(data); |
| 457 |
} |
| 458 |
self.invoke_post_runrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]invoke_post_run().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 459 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
/// A signal that can be shared between thread to stop or wakeup a running |
| 464 |
/// event loop |
| 465 |
#[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:)] |
| 466 |
pub struct LoopSignalrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal# { |
| 467 |
signalrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal#signal.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<AtomicBoolrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicBool#>, |
| 468 |
pingrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal#ping.: craterust-analyzer cargo calloop 0.10.5 crate/::sourcesrust-analyzer cargo calloop 0.10.5 sources/::pingrust-analyzer cargo calloop 0.10.5 sources/ping/::Pingrust-analyzer cargo calloop 0.10.5 sources/ping/Ping#, |
| 469 |
} |
| 470 |
|
| 471 |
impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for LoopSignalrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal# { |
| 472 |
#[cfg_attr(coverage, no_coverage)] |
| 473 |
fn fmtrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[LoopSignal][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 474 |
f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("LoopSignal { ... }") |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
impl LoopSignalrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal# { |
| 479 |
/// Stop the event loop |
| 480 |
/// |
| 481 |
/// Once this method is called, the next time the event loop has finished |
| 482 |
/// waiting for events, it will return rather than starting to wait again. |
| 483 |
/// |
| 484 |
/// This is only usefull if you are using the `EventLoop::run()` method. |
| 485 |
pub fn stoprust-analyzer cargo calloop 0.10.5 loop_logic/impl#[LoopSignal]stop().(&self) { |
| 486 |
self.signalrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal#signal..storerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicBool]store().(true, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Releaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Release#); |
| 487 |
} |
| 488 |
|
| 489 |
/// Wake up the event loop |
| 490 |
/// |
| 491 |
/// This sends a dummy event to the event loop to simulate the reception |
| 492 |
/// of an event, making the wait return early. Called after `stop()`, this |
| 493 |
/// ensures the event loop will terminate quickly if you specified a long |
| 494 |
/// timeout (or no timeout at all) to the `dispatch` or `run` method. |
| 495 |
pub fn wakeuprust-analyzer cargo calloop 0.10.5 loop_logic/impl#[LoopSignal]wakeup().(&self) { |
| 496 |
self.pingrust-analyzer cargo calloop 0.10.5 loop_logic/LoopSignal#ping..pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
#[cfg(test)] |
| 501 |
mod testsrust-analyzer cargo calloop 0.10.5 loop_logic/tests/ { |
| 502 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#; |
| •503 |
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/::IntoRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/IntoRawFd#; |
| •504 |
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/::BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#; |
| 505 |
|
| 506 |
use craterust-analyzer cargo calloop 0.10.5 crate/::{ |
| 507 |
genericrust-analyzer cargo calloop 0.10.5 sources/generic/::Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#, pingrust-analyzer cargo calloop 0.10.5 sources/ping/::*, Dispatcherrust-analyzer cargo calloop 0.10.5 sources/Dispatcher#, Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#, Moderust-analyzer cargo calloop 0.10.5 sys/Mode#, Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#, Readinessrust-analyzer cargo calloop 0.10.5 sys/Readiness#, |
| 508 |
RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#, Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#, TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#, |
| 509 |
}; |
| 510 |
|
| 511 |
use superrust-analyzer cargo calloop 0.10.5 loop_logic/::EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#; |
| 512 |
|
| 513 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 514 |
fn dispatch_idlerust-analyzer cargo calloop 0.10.5 loop_logic/tests/dispatch_idle().() { |
| 515 |
let mut event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 516 |
|
| 517 |
let mut dispatched = false; |
| 518 |
|
| 519 |
event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().().insert_idlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_idle().(|d| { |
| 520 |
*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().d = true; |
| 521 |
}); |
| 522 |
|
| 523 |
event_loop |
| 524 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.), &mut dispatched) |
| 525 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 526 |
|
| 527 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dispatched); |
| 528 |
} |
| 529 |
|
| 530 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 531 |
fn cancel_idlerust-analyzer cargo calloop 0.10.5 loop_logic/tests/cancel_idle().() { |
| 532 |
let mut event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 533 |
|
| 534 |
let mut dispatched = false; |
| 535 |
|
| 536 |
let handle = event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().(); |
| 537 |
let idle = handle.insert_idlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_idle().(move |d| { |
| 538 |
*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().d = true; |
| 539 |
}); |
| 540 |
|
| 541 |
idle.cancelrust-analyzer cargo calloop 0.10.5 sources/impl#[`Idle<'i>`]cancel().(); |
| 542 |
|
| 543 |
event_loop |
| 544 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 545 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 546 |
|
| 547 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dispatched); |
| 548 |
} |
| 549 |
|
| 550 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 551 |
fn wakeuprust-analyzer cargo calloop 0.10.5 loop_logic/tests/wakeup().() { |
| 552 |
let mut event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 553 |
|
| 554 |
let signal = event_loop.get_signalrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]get_signal().(); |
| 555 |
|
| 556 |
::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/spawn().(move || { |
| 557 |
::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::sleeprust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/sleep().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(500)); |
| 558 |
signal.wakeuprust-analyzer cargo calloop 0.10.5 loop_logic/impl#[LoopSignal]wakeup().(); |
| 559 |
}); |
| 560 |
|
| 561 |
// the test should return |
| 562 |
event_loop.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &mut ()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 563 |
} |
| 564 |
|
| 565 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 566 |
fn wakeup_stoprust-analyzer cargo calloop 0.10.5 loop_logic/tests/wakeup_stop().() { |
| 567 |
let mut event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 568 |
|
| 569 |
let signal = event_loop.get_signalrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]get_signal().(); |
| 570 |
|
| 571 |
::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/spawn().(move || { |
| 572 |
::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::sleeprust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/sleep().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(500)); |
| 573 |
signal.stoprust-analyzer cargo calloop 0.10.5 loop_logic/impl#[LoopSignal]stop().(); |
| 574 |
signal.wakeuprust-analyzer cargo calloop 0.10.5 loop_logic/impl#[LoopSignal]wakeup().(); |
| 575 |
}); |
| 576 |
|
| 577 |
// the test should return |
| 578 |
event_loop.runrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]run().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &mut (), |_| {}).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 579 |
} |
| 580 |
|
| 581 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 582 |
fn insert_bad_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/tests/insert_bad_source().() { |
| 583 |
let event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::<()>::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 584 |
let ret = event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().().insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().( |
| 585 |
craterust-analyzer cargo calloop 0.10.5 crate/::sourcesrust-analyzer cargo calloop 0.10.5 sources/::genericrust-analyzer cargo calloop 0.10.5 sources/generic/::Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#::newrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F>`]new().(420, Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#::READrust-analyzer cargo calloop 0.10.5 sys/impl#[Interest]READ., Moderust-analyzer cargo calloop 0.10.5 sys/Mode#::Levelrust-analyzer cargo calloop 0.10.5 sys/Mode#Level#), |
| 586 |
|_, _, _| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue#), |
| 587 |
); |
| 588 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ret.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 589 |
} |
| 590 |
|
| 591 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| •592 |
#[ignore] |
| 593 |
fn insert_source_no_interestrust-analyzer cargo calloop 0.10.5 loop_logic/tests/insert_source_no_interest().() { |
| 594 |
let event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::<()>::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 595 |
let ret = event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().().insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().( |
| 596 |
craterust-analyzer cargo calloop 0.10.5 crate/::sourcesrust-analyzer cargo calloop 0.10.5 sources/::genericrust-analyzer cargo calloop 0.10.5 sources/generic/::Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#::newrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F>`]new().(0, Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#::EMPTYrust-analyzer cargo calloop 0.10.5 sys/impl#[Interest]EMPTY., Moderust-analyzer cargo calloop 0.10.5 sys/Mode#::Levelrust-analyzer cargo calloop 0.10.5 sys/Mode#Level#), |
| 597 |
|_, _, _| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue#), |
| 598 |
); |
| 599 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ret.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 600 |
} |
| 601 |
|
| 602 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 603 |
fn disarm_rearmrust-analyzer cargo calloop 0.10.5 loop_logic/tests/disarm_rearm().() { |
| 604 |
let mut event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::<bool>::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 605 |
let (ping, ping_source) = make_pingrust-analyzer cargo calloop 0.10.5 sources/ping/make_ping().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 606 |
|
| 607 |
let ping_token = event_loop |
| 608 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().() |
| 609 |
.insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().(ping_source, |(), &mut (), dispatched| { |
| 610 |
*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().dispatched = true; |
| 611 |
}) |
| 612 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 613 |
|
| 614 |
ping.pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 615 |
let mut dispatched = false; |
| 616 |
event_loop |
| 617 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 618 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 619 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dispatched); |
| 620 |
|
| 621 |
// disable the source |
| 622 |
ping.pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 623 |
event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().().disablerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]disable().(&ping_token).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 624 |
let mut dispatched = false; |
| 625 |
event_loop |
| 626 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 627 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 628 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dispatched); |
| 629 |
|
| 630 |
// disabling it again is an error |
| 631 |
event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().().disablerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]disable().(&ping_token).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(); |
| 632 |
|
| 633 |
// reenable it, the previous ping now gets dispatched |
| 634 |
event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().().enablerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]enable().(&ping_token).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 635 |
let mut dispatched = false; |
| 636 |
event_loop |
| 637 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 638 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 639 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dispatched); |
| 640 |
} |
| 641 |
|
| 642 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 643 |
fn multiple_tokensrust-analyzer cargo calloop 0.10.5 loop_logic/tests/multiple_tokens().() { |
| 644 |
struct DoubleSourcerust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource# { |
| 645 |
ping1rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping1.: PingSourcerust-analyzer cargo calloop 0.10.5 sources/ping/PingSource#, |
| 646 |
ping2rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping2.: PingSourcerust-analyzer cargo calloop 0.10.5 sources/ping/PingSource#, |
| 647 |
} |
| 648 |
|
| 649 |
impl craterust-analyzer cargo calloop 0.10.5 crate/::EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource# for DoubleSourcerust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource# { |
| 650 |
type Eventrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]Event# = u32; |
| 651 |
type Metadatarust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]Metadata# = (); |
| 652 |
type Retrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]Ret# = (); |
| 653 |
type Errorrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]Error# = PingErrorrust-analyzer cargo calloop 0.10.5 sources/ping/PingError#; |
| 654 |
|
| 655 |
fn process_eventsrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]process_events().<F>( |
| 656 |
&mut self, |
| 657 |
readiness: Readinessrust-analyzer cargo calloop 0.10.5 sys/Readiness#, |
| 658 |
token: Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#, |
| 659 |
mut callback: F, |
| 660 |
) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#, Selfrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]::Errorrust-analyzer cargo calloop 0.10.5 sources/EventSource#Error#> |
| 661 |
where |
| 662 |
F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Selfrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]::Eventrust-analyzer cargo calloop 0.10.5 sources/EventSource#Event#, &mut Selfrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]::Metadatarust-analyzer cargo calloop 0.10.5 sources/EventSource#Metadata#) -> Selfrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]::Retrust-analyzer cargo calloop 0.10.5 sources/EventSource#Ret#, |
| 663 |
{ |
| 664 |
self.ping1rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping1. |
| 665 |
.process_eventsrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]process_events().(readiness, token, |(), &mut ()| callback(1, &mut ()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 666 |
self.ping2rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping2. |
| 667 |
.process_eventsrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]process_events().(readiness, token, |(), &mut ()| callback(2, &mut ()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 668 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue#) |
| 669 |
} |
| 670 |
|
| 671 |
fn registerrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]register().( |
| 672 |
&mut self, |
| 673 |
poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, |
| 674 |
token_factory: &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#, |
| 675 |
) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 676 |
self.ping1rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping1..registerrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]register().(poll, token_factory)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 677 |
self.ping2rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping2..registerrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]register().(poll, token_factory)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 678 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 679 |
} |
| 680 |
|
| 681 |
fn reregisterrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]reregister().( |
| 682 |
&mut self, |
| 683 |
poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, |
| 684 |
token_factory: &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#, |
| 685 |
) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 686 |
self.ping1rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping1..reregisterrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]reregister().(poll, token_factory)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 687 |
self.ping2rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping2..reregisterrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]reregister().(poll, token_factory)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 688 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 689 |
} |
| 690 |
|
| 691 |
fn unregisterrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DoubleSource][EventSource]unregister().(&mut self, poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 692 |
self.ping1rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping1..unregisterrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]unregister().(poll)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 693 |
self.ping2rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping2..unregisterrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]unregister().(poll)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 694 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
let mut event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::<u32>::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 699 |
|
| 700 |
let (ping1, source1) = make_pingrust-analyzer cargo calloop 0.10.5 sources/ping/make_ping().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 701 |
let (ping2, source2) = make_pingrust-analyzer cargo calloop 0.10.5 sources/ping/make_ping().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 702 |
|
| 703 |
let source = DoubleSourcerust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource# { |
| 704 |
ping1rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping1.: source1, |
| 705 |
ping2rust-analyzer cargo calloop 0.10.5 loop_logic/tests/DoubleSource#ping2.: source2, |
| 706 |
}; |
| 707 |
|
| 708 |
event_loop |
| 709 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().() |
| 710 |
.insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().(source, |i, _, d| { |
| 711 |
eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Dispatching {}", i); |
| 712 |
*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().d rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().i |
| 713 |
}) |
| 714 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 715 |
|
| 716 |
let mut dispatched = 0; |
| 717 |
ping1.pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 718 |
event_loop |
| 719 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 720 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 721 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(dispatched, 1); |
| 722 |
|
| 723 |
dispatched = 0; |
| 724 |
ping2.pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 725 |
event_loop |
| 726 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 727 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 728 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(dispatched, 2); |
| 729 |
|
| 730 |
dispatched = 0; |
| 731 |
ping1.pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 732 |
ping2.pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 733 |
event_loop |
| 734 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 735 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 736 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(dispatched, 3); |
| 737 |
} |
| 738 |
|
| 739 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 740 |
fn change_interestsrust-analyzer cargo calloop 0.10.5 loop_logic/tests/change_interests().() { |
| 741 |
use nixrust-analyzer cargo nix 0.30.1 crate/::sysrust-analyzer cargo nix 0.30.1 sys/::socketrust-analyzer cargo nix 0.30.1 sys/socket/::{recvrust-analyzer cargo nix 0.30.1 sys/socket/recv()., socketpairrust-analyzer cargo nix 0.30.1 sys/socket/socketpair()., AddressFamilyrust-analyzer cargo nix 0.30.1 sys/socket/addr/AddressFamily#, MsgFlagsrust-analyzer cargo nix 0.30.1 sys/socket/MsgFlags#, SockFlagrust-analyzer cargo nix 0.30.1 sys/socket/SockFlag#, SockTyperust-analyzer cargo nix 0.30.1 sys/socket/SockType#}; |
| 742 |
use nixrust-analyzer cargo nix 0.30.1 crate/::unistdrust-analyzer cargo nix 0.30.1 unistd/::writerust-analyzer cargo nix 0.30.1 unistd/write().; |
| 743 |
let mut event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::<bool>::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 744 |
|
| 745 |
let (sock1, sock2) = socketpairrust-analyzer cargo nix 0.30.1 sys/socket/socketpair().( |
| 746 |
AddressFamilyrust-analyzer cargo nix 0.30.1 sys/socket/addr/AddressFamily#::Unixrust-analyzer cargo nix 0.30.1 sys/socket/addr/AddressFamily#Unix#, |
| 747 |
SockTyperust-analyzer cargo nix 0.30.1 sys/socket/SockType#::Streamrust-analyzer cargo nix 0.30.1 sys/socket/SockType#Stream#, |
| 748 |
Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 749 |
SockFlagrust-analyzer cargo nix 0.30.1 sys/socket/SockFlag#::emptyrust-analyzer cargo nix 0.30.1 sys/socket/impl#[SockFlag]empty().(), // recv with DONTWAIT will suffice for platforms without SockFlag::SOCK_NONBLOCKING such as macOS |
| 750 |
) |
| 751 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| •752 |
let sock1 = sock1.into_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][IntoRawFd]into_raw_fd().(); |
| 753 |
let sock2 = sock2.into_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][IntoRawFd]into_raw_fd().(); |
| 754 |
|
| 755 |
let source = Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#::newrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F>`]new().(sock1, Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#::READrust-analyzer cargo calloop 0.10.5 sys/impl#[Interest]READ., Moderust-analyzer cargo calloop 0.10.5 sys/Mode#::Levelrust-analyzer cargo calloop 0.10.5 sys/Mode#Level#); |
| 756 |
let dispatcher = Dispatcherrust-analyzer cargo calloop 0.10.5 sources/Dispatcher#::newrust-analyzer cargo calloop 0.10.5 sources/impl#[`Dispatcher<'a, S, Data>`]new().(source, |_, &mut fd, dispatched| { |
| 757 |
*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().dispatched = true; |
| 758 |
// read all contents available to drain the socket |
| 759 |
let mut buf = [0u8; 32]; |
| 760 |
loop { |
| 761 |
match recvrust-analyzer cargo nix 0.30.1 sys/socket/recv().(fd, &mut buf, MsgFlagsrust-analyzer cargo nix 0.30.1 sys/socket/MsgFlags#::MSG_DONTWAITrust-analyzer cargo nix 0.30.1 sys/socket/impl#[MsgFlags]MSG_DONTWAIT.) { |
| 762 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0) => break, // closed pipe, we are now inert |
| 763 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => {} |
| 764 |
Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 765 |
let e: 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/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error# = e.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 766 |
if e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().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/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::WouldBlockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#WouldBlock# { |
| 767 |
break; |
| 768 |
// nothing more to read |
| 769 |
} else { |
| 770 |
// propagate error |
| 771 |
return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e); |
| 772 |
} |
| 773 |
} |
| 774 |
} |
| 775 |
} |
| 776 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue#) |
| 777 |
}); |
| 778 |
|
| 779 |
let sock_token_1 = event_loop |
| 780 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().() |
| 781 |
.register_dispatcherrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]register_dispatcher().(dispatcher.clonerust-analyzer cargo calloop 0.10.5 sources/impl#[`Dispatcher<'a, S, Data>`][Clone]clone().()) |
| 782 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 783 |
|
| 784 |
// first dispatch, nothing is readable |
| 785 |
let mut dispatched = false; |
| 786 |
event_loop |
| 787 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 788 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 789 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dispatched); |
| 790 |
|
| 791 |
// write something, the socket becomes readable |
| •792 |
writerust-analyzer cargo nix 0.30.1 unistd/write().(unsafe { BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#::borrow_rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`]borrow_raw().(sock2) }, &[1, 2, 3]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 793 |
dispatched = false; |
| 794 |
event_loop |
| 795 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 796 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 797 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dispatched); |
| 798 |
|
| 799 |
// All has been read, no longer readable |
| 800 |
dispatched = false; |
| 801 |
event_loop |
| 802 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 803 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 804 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dispatched); |
| 805 |
|
| 806 |
// change the interests for writability instead |
| 807 |
dispatcher.as_source_mutrust-analyzer cargo calloop 0.10.5 sources/impl#[`Dispatcher<'a, S, Data>`]as_source_mut().().interestrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#interest. = Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#::WRITErust-analyzer cargo calloop 0.10.5 sys/impl#[Interest]WRITE.; |
| 808 |
event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().().updaterust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]update().(&sock_token_1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 809 |
|
| 810 |
// the socket is writable |
| 811 |
dispatched = false; |
| 812 |
event_loop |
| 813 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 814 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 815 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dispatched); |
| 816 |
|
| 817 |
// change back to readable |
| 818 |
dispatcher.as_source_mutrust-analyzer cargo calloop 0.10.5 sources/impl#[`Dispatcher<'a, S, Data>`]as_source_mut().().interestrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#interest. = Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#::READrust-analyzer cargo calloop 0.10.5 sys/impl#[Interest]READ.; |
| 819 |
event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().().updaterust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]update().(&sock_token_1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 820 |
|
| 821 |
// the socket is not readable |
| 822 |
dispatched = false; |
| 823 |
event_loop |
| 824 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut dispatched) |
| 825 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 826 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dispatched); |
| 827 |
} |
| 828 |
|
| 829 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 830 |
fn kill_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/tests/kill_source().() { |
| 831 |
let mut event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<RegistrationTokenrust-analyzer cargo calloop 0.10.5 loop_logic/RegistrationToken#>>::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 832 |
|
| 833 |
let handle = event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().(); |
| 834 |
let (ping, ping_source) = make_pingrust-analyzer cargo calloop 0.10.5 sources/ping/make_ping().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 835 |
let ping_token = event_loop |
| 836 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().() |
| 837 |
.insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().(ping_source, move |(), &mut (), opt_src| { |
| 838 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(src) = opt_src.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() { |
| 839 |
handle.removerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]remove().(src); |
| 840 |
} |
| 841 |
}) |
| 842 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 843 |
|
| 844 |
ping.pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 845 |
|
| 846 |
let mut opt_src = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ping_token); |
| 847 |
|
| 848 |
event_loop.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut opt_src).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 849 |
|
| 850 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(opt_src.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 851 |
} |
| 852 |
|
| 853 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 854 |
fn non_static_datarust-analyzer cargo calloop 0.10.5 loop_logic/tests/non_static_data().() { |
| 855 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::mpscrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/; |
| 856 |
|
| 857 |
let (sender, receiver) = mpscrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/::channelrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/channel().(); |
| 858 |
|
| 859 |
{ |
| 860 |
struct RefSenderrust-analyzer cargo calloop 0.10.5 loop_logic/tests/RefSender#<'a>(&'a mpscrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/::Senderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/Sender#<()>); |
| 861 |
let mut ref_sender = RefSenderrust-analyzer cargo calloop 0.10.5 loop_logic/tests/RefSender#(&sender); |
| 862 |
|
| 863 |
let mut event_loop = EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::<RefSenderrust-analyzer cargo calloop 0.10.5 loop_logic/tests/RefSender#<'_>>::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 864 |
let (ping, ping_source) = make_pingrust-analyzer cargo calloop 0.10.5 sources/ping/make_ping().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 865 |
let _ping_token = event_loop |
| 866 |
.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().() |
| 867 |
.insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().(ping_source, |_, _, ref_sender| { |
| 868 |
ref_sender.0rust-analyzer cargo calloop 0.10.5 loop_logic/tests/RefSender#0..sendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/impl#[`Sender<T>`]send().(()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 869 |
}) |
| 870 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 871 |
|
| 872 |
ping.pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 873 |
|
| 874 |
event_loop |
| 875 |
.dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO., &mut ref_sender) |
| 876 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 877 |
} |
| 878 |
|
| 879 |
receiver.recvrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/impl#[`Receiver<T>`]recv().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 880 |
// sender still usable (e.g. for another EventLoop) |
| 881 |
droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(sender); |
| 882 |
} |
| 883 |
|
| 884 |
// A dummy EventSource to test insertion and removal of sources |
| 885 |
struct DummySourcerust-analyzer cargo calloop 0.10.5 loop_logic/tests/DummySource#; |
| 886 |
|
| 887 |
impl craterust-analyzer cargo calloop 0.10.5 crate/::EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource# for DummySourcerust-analyzer cargo calloop 0.10.5 loop_logic/tests/DummySource# { |
| 888 |
type Eventrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]Event# = (); |
| 889 |
type Metadatarust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]Metadata# = (); |
| 890 |
type Retrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]Ret# = (); |
| 891 |
type Errorrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]Error# = craterust-analyzer cargo calloop 0.10.5 crate/::Errorrust-analyzer cargo calloop 0.10.5 error/Error#; |
| 892 |
|
| 893 |
fn process_eventsrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]process_events().<F>( |
| 894 |
&mut self, |
| 895 |
_: Readinessrust-analyzer cargo calloop 0.10.5 sys/Readiness#, |
| 896 |
_: Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#, |
| 897 |
mut callback: F, |
| 898 |
) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#, Selfrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]::Errorrust-analyzer cargo calloop 0.10.5 sources/EventSource#Error#> |
| 899 |
where |
| 900 |
F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Selfrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]::Eventrust-analyzer cargo calloop 0.10.5 sources/EventSource#Event#, &mut Selfrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]::Metadatarust-analyzer cargo calloop 0.10.5 sources/EventSource#Metadata#) -> Selfrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]::Retrust-analyzer cargo calloop 0.10.5 sources/EventSource#Ret#, |
| 901 |
{ |
| 902 |
callback((), &mut ()); |
| 903 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue#) |
| 904 |
} |
| 905 |
|
| 906 |
fn registerrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]register().(&mut self, _: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, _: &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 907 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 908 |
} |
| 909 |
|
| 910 |
fn reregisterrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]reregister().(&mut self, _: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, _: &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 911 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 912 |
} |
| 913 |
|
| 914 |
fn unregisterrust-analyzer cargo calloop 0.10.5 loop_logic/tests/impl#[DummySource][EventSource]unregister().(&mut self, _: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 915 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 916 |
} |
| 917 |
} |
| 918 |
} |