Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit d7d5b6f

Browse files
m-hilgendorfaskeksa
authored andcommitted
removed EventIterator and replaced with impl Trait syntax (#111)
1 parent 25acc3d commit d7d5b6f

File tree

1 file changed

+3
-33
lines changed

1 file changed

+3
-33
lines changed

src/api.rs

+3-33
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::os::raw::c_void;
44

55
use self::consts::*;
66
use plugin::Plugin;
7-
use std::marker::PhantomData;
87

98
/// Constant values
109
#[allow(missing_docs)] // For obvious constants
@@ -405,7 +404,6 @@ pub struct Events {
405404

406405
impl Events {
407406
#[inline]
408-
#[allow(dead_code)]
409407
pub(crate) fn events_raw(&self) -> &[*const Event] {
410408
use std::slice;
411409
unsafe {
@@ -453,37 +451,9 @@ impl Events {
453451
/// # }
454452
/// ```
455453
#[inline]
456-
pub fn events(&self) -> EventIterator {
457-
let ptr = self.events.as_ptr() as *const *const Event;
458-
EventIterator {
459-
current: ptr,
460-
end: unsafe { ptr.offset(self.num_events as isize) },
461-
_marker: PhantomData,
462-
}
463-
}
464-
}
465-
466-
/// An iterator over events, returned by `api::Events::events`
467-
pub struct EventIterator<'a> {
468-
current: *const *const Event,
469-
end: *const *const Event,
470-
_marker: PhantomData<&'a Event>,
471-
}
472-
473-
impl<'a> Iterator for EventIterator<'a> {
474-
type Item = ::event::Event<'a>;
475-
476-
fn next(&mut self) -> Option<Self::Item> {
477-
if self.current == self.end {
478-
None
479-
} else {
480-
let event = unsafe {
481-
let e = **self.current;
482-
self.current = self.current.offset(1);
483-
e
484-
};
485-
Some(event.into())
486-
}
454+
#[allow(clippy::needless_lifetimes)]
455+
pub fn events<'a>(&'a self) -> impl Iterator<Item = ::event::Event<'a>> {
456+
self.events_raw().iter().map(|ptr| unsafe { **ptr }.into())
487457
}
488458
}
489459

0 commit comments

Comments
 (0)