Debian Codegraph @

src/sources/generic.rs

raw symbols SCIP
1 //! A generic event source wrapping an IO objects or file descriptor
2 //!
3 //! You can use this general purpose adapter around file-descriptor backed objects to
4 //! insert into an [`EventLoop`](crate::EventLoop).
5 //!
6 //! The event generated by this [`Generic`] event source are the [`Readiness`](crate::Readiness)
7 //! notification itself, and the monitored object is provided to your callback as the second
8 //! argument.
9 //!
10 //! ```
11 //! # extern crate calloop;
12 //! use calloop::{generic::Generic, Interest, Mode, PostAction};
13 //!
14 //! # fn main() {
15 //! # let mut event_loop = calloop::EventLoop::<()>::try_new()
16 //! # .expect("Failed to initialize the event loop!");
17 //! # let handle = event_loop.handle();
18 //! # let io_object = 0;
19 //! handle.insert_source(
20 //! // wrap your IO object in a Generic, here we register for read readiness
21 //! // in level-triggering mode
22 //! Generic::new(io_object, Interest::READ, Mode::Level),
23 //! |readiness, io_object, shared_data| {
24 //! // The first argument of the callback is a Readiness
25 //! // The second is a &mut reference to your object
26 //!
27 //! // your callback needs to return a Result<PostAction, std::io::Error>
28 //! // if it returns an error, the event loop will consider this event
29 //! // event source as erroring and report it to the user.
30 //! Ok(PostAction::Continue)
31 //! }
32 //! );
33 //! # }
34 //! ```
35 //!
36 //! It can also help you implementing your own event sources: just have
37 //! these `Generic<_>` as fields of your event source, and delegate the
38 //! [`EventSource`](crate::EventSource) implementation to them.
39 //!
40 //! If you need to directly work with a [`RawFd`](std::os::unix::io::RawFd), rather than an
41 //! FD-backed object, see [`Generic::from_fd`](Generic#method.from_fd).
42
43 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, 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#};
44
45 use craterust-analyzer cargo calloop 0.10.5 crate/::{EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource#, 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#, Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#, TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#};
46
47 /// A generic event source wrapping a FD-backed type
48 #[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:)]
49 pub struct Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#<F: AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#, 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#> {
50 /// The wrapped FD-backed type
51 pub filerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#file.: F,
52 /// The programmed interest
53 pub interestrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#interest.: Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#,
54 /// The programmed mode
55 pub moderust-analyzer cargo calloop 0.10.5 sources/generic/Generic#mode.: Moderust-analyzer cargo calloop 0.10.5 sys/Mode#,
56
57 // This token is used by the event loop logic to look up this source when an
58 // event occurs.
59 tokenrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#token.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#>,
60
61 // This allows us to make the associated error and return types generic.
62 _error_typerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#_error_type.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<E>,
63 }
64
65 impl<F: AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#> Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#<F, 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#> {
66 /// Wrap a FD-backed type into a `Generic` event source that uses
67 /// [`std::io::Error`] as its error type.
68 pub fn newrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F>`]new().(file: F, interest: Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#, mode: Moderust-analyzer cargo calloop 0.10.5 sys/Mode#) -> Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#<F, 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#> {
69 Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic# {
70 filerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#file.,
71 interestrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#interest.,
72 moderust-analyzer cargo calloop 0.10.5 sources/generic/Generic#mode.,
73 tokenrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#token.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
74 _error_typerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#_error_type.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/impl#[`PhantomData<T>`][Default]default().(),
75 }
76 }
77
78 /// Wrap a FD-backed type into a `Generic` event source using an arbitrary error type.
79 pub fn new_with_errorrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F>`]new_with_error().<E>(file: F, interest: Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#, mode: Moderust-analyzer cargo calloop 0.10.5 sys/Mode#) -> Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#<F, E> {
80 Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic# {
81 filerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#file.,
82 interestrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#interest.,
83 moderust-analyzer cargo calloop 0.10.5 sources/generic/Generic#mode.,
84 tokenrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#token.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
85 _error_typerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#_error_type.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/impl#[`PhantomData<T>`][Default]default().(),
86 }
87 }
88 }
89
90 impl<F: AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#, E> Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#<F, E> {
91 /// Unwrap the `Generic` source to retrieve the underlying type
92 pub fn unwraprust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`]unwrap().(self) -> F {
93 self.filerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#file.
94 }
95 }
96
97 impl<F, E> EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource# for Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#<F, E>
98 where
99 F: AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#,
100 E: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>>,
101 {
102 type Eventrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]Event# = Readinessrust-analyzer cargo calloop 0.10.5 sys/Readiness#;
103 type Metadatarust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]Metadata# = F;
104 type Retrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]Ret# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#, E>;
105 type Errorrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]Error# = E;
106
107 fn process_eventsrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]process_events().<C>(
108 &mut self,
109 readiness: Readinessrust-analyzer cargo calloop 0.10.5 sys/Readiness#,
110 token: Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#,
111 mut callback: C,
112 ) -> 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 sources/generic/impl#[`Generic<F, E>`][EventSource]::Errorrust-analyzer cargo calloop 0.10.5 sources/EventSource#Error#>
113 where
114 C: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Selfrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]::Eventrust-analyzer cargo calloop 0.10.5 sources/EventSource#Event#, &mut Selfrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]::Metadatarust-analyzer cargo calloop 0.10.5 sources/EventSource#Metadata#) -> Selfrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]::Retrust-analyzer cargo calloop 0.10.5 sources/EventSource#Ret#,
115 {
116 // If the token is invalid or not ours, skip processing.
117 if self.tokenrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#token. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) {
118 return 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#);
119 }
120
121 callback(readiness, &mut self.filerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#file.)
122 }
123
124 fn registerrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]register().(&mut self, poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, token_factory: &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#<()> {
125 let token = token_factory.tokenrust-analyzer cargo calloop 0.10.5 sys/impl#[TokenFactory]token().();
126
127 poll.registerrust-analyzer cargo calloop 0.10.5 sys/impl#[Poll]register().(self.filerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#file..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#as_raw_fd().(), self.interestrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#interest., self.moderust-analyzer cargo calloop 0.10.5 sources/generic/Generic#mode., token)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
128
129 self.tokenrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#token. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token);
130 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
131 }
132
133 fn reregisterrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]reregister().(
134 &mut self,
135 poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#,
136 token_factory: &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#,
137 ) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> {
138 let token = token_factory.tokenrust-analyzer cargo calloop 0.10.5 sys/impl#[TokenFactory]token().();
139
140 poll.reregisterrust-analyzer cargo calloop 0.10.5 sys/impl#[Poll]reregister().(self.filerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#file..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#as_raw_fd().(), self.interestrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#interest., self.moderust-analyzer cargo calloop 0.10.5 sources/generic/Generic#mode., token)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
141
142 self.tokenrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#token. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token);
143 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
144 }
145
146 fn unregisterrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][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#<()> {
147 poll.unregisterrust-analyzer cargo calloop 0.10.5 sys/impl#[Poll]unregister().(self.filerust-analyzer cargo calloop 0.10.5 sources/generic/Generic#file..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#as_raw_fd().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
148 self.tokenrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#token. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
149 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
150 }
151 }
152
153 #[cfg(test)]
154 mod testsrust-analyzer cargo calloop 0.10.5 sources/generic/tests/ {
155 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/::{Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#};
156
157 use superrust-analyzer cargo calloop 0.10.5 sources/generic/::Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#;
158 use craterust-analyzer cargo calloop 0.10.5 crate/::{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#, PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#};
159 #[cfg(unix)]
160 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
161 fn dispatch_unixrust-analyzer cargo calloop 0.10.5 sources/generic/tests/dispatch_unix().() {
162 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/::netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/::UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#;
163
164 let mut event_loop = craterust-analyzer cargo calloop 0.10.5 crate/::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().();
165
166 let handle = event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().();
167
168 let (mut tx, rx) = UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#::pairrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream]pair().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
169
170 let generic = Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#::newrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F>`]new().(rx, 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#);
171
172 let mut dispached = false;
173
174 let _generic_token = handle
175 .insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().(generic, move |readiness, file, d| {
176 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(readiness.readablerust-analyzer cargo calloop 0.10.5 sys/Readiness#readable.);
177 // we have not registered for writability
178 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().readiness.writablerust-analyzer cargo calloop 0.10.5 sys/Readiness#writable.);
179 let mut buffer = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; 10];
180 let ret = file.readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream][Read]read().(&mut buffer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
181 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, 6);
182 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buffer[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...6]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., &[1, 2, 3, 4, 5, 6]);
183
184 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().d = true;
185 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#)
186 })
187 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
188
189 event_loop
190 .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#(::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#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.), &mut dispached)
191 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
192
193 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().dispached);
194
195 let ret = tx.writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream][Write]write().(&[1, 2, 3, 4, 5, 6]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
196 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, 6);
197 tx.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream][Write]flush().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
198
199 event_loop
200 .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#(::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#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.), &mut dispached)
201 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
202
203 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dispached);
204 }
205
206 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
207 fn register_deregister_unixrust-analyzer cargo calloop 0.10.5 sources/generic/tests/register_deregister_unix().() {
208 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/::netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/::UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#;
209
210 let mut event_loop = craterust-analyzer cargo calloop 0.10.5 crate/::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().();
211
212 let handle = event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().();
213
214 let (mut tx, rx) = UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#::pairrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream]pair().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
215
216 let generic = Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#::newrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F>`]new().(rx, 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#);
217 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().(generic, move |_, _, d| {
218 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().d = true;
219 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#)
220 });
221
222 let mut dispached = false;
223
224 let generic_token = handle.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().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
225
226 event_loop
227 .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#(::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#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.), &mut dispached)
228 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
229
230 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().dispached);
231
232 // remove the source, and then write something
233
234 event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().().removerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]remove().(generic_token);
235
236 let ret = tx.writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream][Write]write().(&[1, 2, 3, 4, 5, 6]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
237 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, 6);
238 tx.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream][Write]flush().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
239
240 event_loop
241 .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#(::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#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.), &mut dispached)
242 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
243
244 // the source has not been dispatched, as the source is no longer here
245 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().dispached);
246
247 // insert it again
248 let generic = dispatcher.into_source_innerrust-analyzer cargo calloop 0.10.5 sources/impl#[`Dispatcher<'a, S, Data>`]into_source_inner().();
249 let _generic_token = handle
250 .insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().(generic, move |readiness, file, d| {
251 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(readiness.readablerust-analyzer cargo calloop 0.10.5 sys/Readiness#readable.);
252 // we have not registered for writability
253 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().readiness.writablerust-analyzer cargo calloop 0.10.5 sys/Readiness#writable.);
254 let mut buffer = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; 10];
255 let ret = file.readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream][Read]read().(&mut buffer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
256 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, 6);
257 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buffer[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...6]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., &[1, 2, 3, 4, 5, 6]);
258
259 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().d = true;
260 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#)
261 })
262 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
263
264 event_loop
265 .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#(::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#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.), &mut dispached)
266 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
267
268 // the has now been properly dispatched
269 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dispached);
270 }
271 }