mirror of
https://git.intege.rs/xlib/x.git
synced 2025-12-05 20:35:01 +00:00
iterate
This commit is contained in:
47
src/data.rs
47
src/data.rs
@@ -38,4 +38,49 @@ pub fn distance(p1: impl IntoUsize, p2: impl IntoUsize) -> usize {
|
||||
Ordering::Greater => p1 - p2,
|
||||
Ordering::Equal => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod pointer_iterator {
|
||||
|
||||
pub trait Pointer {
|
||||
type IterType;
|
||||
fn into_iter(self) -> Self::IterType;
|
||||
}
|
||||
|
||||
pub struct PIter<T>(*const T);
|
||||
pub struct PIterMut<T>(*mut T);
|
||||
|
||||
impl<T: 'static> Iterator for PIter<T> {
|
||||
type Item = &'static T;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
unsafe {
|
||||
let r = Some(&*self.0);
|
||||
self.0 = self.0.offset(1isize);
|
||||
r
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static> Iterator for PIterMut<T> {
|
||||
type Item = &'static mut T;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
unsafe {
|
||||
let r = Some(&mut *self.0);
|
||||
self.0 = self.0.offset(1isize);
|
||||
r
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T> Pointer for *const T {
|
||||
type IterType = PIter<T>;
|
||||
fn into_iter(self) -> Self::IterType { PIter(self) }
|
||||
}
|
||||
impl<T> Pointer for *mut T {
|
||||
type IterType = PIterMut<T>;
|
||||
fn into_iter(self) -> Self::IterType { PIterMut(self) }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iterate<T: pointer_iterator::Pointer>(pointer: T) -> T::IterType {
|
||||
pointer.into_iter()
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ pub use cffi::*;
|
||||
pub mod win32;
|
||||
|
||||
#[cfg(feature = "win32")]
|
||||
pub use win32::{ image_base, image_header, find_kernel32 };
|
||||
pub use win32::{ image_base, image_header, find_kernel32, process_executable };
|
||||
|
||||
|
||||
/// re-export the signature macro
|
||||
|
||||
Reference in New Issue
Block a user