summaryrefslogtreecommitdiffstats
path: root/third_party/rust/neqo-common/src/event.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/neqo-common/src/event.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/neqo-common/src/event.rs')
-rw-r--r--third_party/rust/neqo-common/src/event.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/third_party/rust/neqo-common/src/event.rs b/third_party/rust/neqo-common/src/event.rs
new file mode 100644
index 0000000000..26052b7571
--- /dev/null
+++ b/third_party/rust/neqo-common/src/event.rs
@@ -0,0 +1,52 @@
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::{iter::Iterator, marker::PhantomData};
+
+/// An event provider is able to generate a stream of events.
+pub trait Provider {
+ type Event;
+
+ /// Get the next event.
+ #[must_use]
+ fn next_event(&mut self) -> Option<Self::Event>;
+
+ /// Determine whether there are pending events.
+ #[must_use]
+ fn has_events(&self) -> bool;
+
+ /// Construct an iterator that produces all events.
+ fn events(&'_ mut self) -> Iter<'_, Self, Self::Event> {
+ Iter::new(self)
+ }
+}
+
+pub struct Iter<'a, P, E>
+where
+ P: ?Sized,
+{
+ p: &'a mut P,
+ _e: PhantomData<E>,
+}
+
+impl<'a, P, E> Iter<'a, P, E>
+where
+ P: Provider<Event = E> + ?Sized,
+{
+ fn new(p: &'a mut P) -> Self {
+ Self { p, _e: PhantomData }
+ }
+}
+
+impl<'a, P, E> Iterator for Iter<'a, P, E>
+where
+ P: Provider<Event = E>,
+{
+ type Item = E;
+ fn next(&mut self) -> Option<Self::Item> {
+ self.p.next_event()
+ }
+}