macro_rules! ffi_iter {
(@impl, struct, $iterator_type:ident($container:ident),) => { ... };
(@impl, struct, $iterator_type:ident($container:ident), mut) => { ... };
(@impl, lifetime, $iterator_type:ident,) => { ... };
(@impl, lifetime, $iterator_type:ident, mut) => { ... };
($iterator_type:ident($container:ident) -> $(($mutability:ident))? $type:ident, len($len_func:path), get($get_func:path)) => { ... };
}Expand description
Generates iterator types for FFI containers.
§Example
mod bindings {
pub enum ContainerType {}
pub enum ContainerItem {}
extern {
pub fn container_name_len(c: *const ContainerType) -> usize;
pub fn container_name_get(c: *const ContainerType, pos: usize) -> *const ContainerItem;
}
}
use bindings::{ContainerType, ContainerItem};
easy_ffi_wrapper::ffi_iter!(
ContainerIter(ContainerType) -> ContainerItem,
len(bindings::container_name_len),
get(bindings::container_name_get)
);The generated type implements: Iterator, DoubleEndedIterator, ExactSizeIterator,
FusedIterator. It can be created from the container type and exposes random access index
function.
§Notes
The std::ops::Index trait cannot be implemented ergnomically due to the following issue:
The item references returned by Index::index cannot outlive the iterator.
In general ffi_iter is inappropriate for use with containers which already implement
Iterator (for example, types in Rust std and core).