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

Commit

Permalink
removed EventIterator and replaced with impl Trait syntax (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-hilgendorf authored and askeksa committed Nov 16, 2019
1 parent 25acc3d commit d7d5b6f
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::os::raw::c_void;

use self::consts::*;
use plugin::Plugin;
use std::marker::PhantomData;

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

impl Events {
#[inline]
#[allow(dead_code)]
pub(crate) fn events_raw(&self) -> &[*const Event] {
use std::slice;
unsafe {
Expand Down Expand Up @@ -453,37 +451,9 @@ impl Events {
/// # }
/// ```
#[inline]
pub fn events(&self) -> EventIterator {
let ptr = self.events.as_ptr() as *const *const Event;
EventIterator {
current: ptr,
end: unsafe { ptr.offset(self.num_events as isize) },
_marker: PhantomData,
}
}
}

/// An iterator over events, returned by `api::Events::events`
pub struct EventIterator<'a> {
current: *const *const Event,
end: *const *const Event,
_marker: PhantomData<&'a Event>,
}

impl<'a> Iterator for EventIterator<'a> {
type Item = ::event::Event<'a>;

fn next(&mut self) -> Option<Self::Item> {
if self.current == self.end {
None
} else {
let event = unsafe {
let e = **self.current;
self.current = self.current.offset(1);
e
};
Some(event.into())
}
#[allow(clippy::needless_lifetimes)]
pub fn events<'a>(&'a self) -> impl Iterator<Item = ::event::Event<'a>> {
self.events_raw().iter().map(|ptr| unsafe { **ptr }.into())
}
}

Expand Down

0 comments on commit d7d5b6f

Please sign in to comment.