use std::fmt;
use ttf2mesh_sys as sys;
pub trait Value<'a> {
type Output: fmt::Debug;
fn val(&self) -> Self::Output;
}
impl<'a> Value<'a> for sys::ttf_mesh__bindgen_ty_1 {
type Output = (f32, f32);
fn val(&self) -> Self::Output {
(self.x, self.y)
}
}
impl<'a> Value<'a> for sys::ttf_mesh__bindgen_ty_2 {
type Output = (i32, i32, i32);
fn val(&self) -> Self::Output {
(self.v1, self.v2, self.v3)
}
}
impl<'a> Value<'a> for sys::ttf_mesh3d__bindgen_ty_1 {
type Output = (f32, f32, f32);
fn val(&self) -> Self::Output {
(self.x, self.y, self.z)
}
}
impl<'a> Value<'a> for sys::ttf_mesh3d__bindgen_ty_2 {
type Output = (i32, i32, i32);
fn val(&self) -> Self::Output {
(self.v1, self.v2, self.v3)
}
}
impl<'a> Value<'a> for sys::ttf_mesh3d__bindgen_ty_3 {
type Output = (f32, f32, f32);
fn val(&self) -> Self::Output {
(self.x, self.y, self.z)
}
}
pub struct DataIterator<'a, T: Value<'a>> {
index: usize,
iterable: &'a [T],
}
impl<'a, T: Value<'a>> DataIterator<'a, T> {
pub(crate) fn new(iterable: &'a [T]) -> Self {
Self { index: 0, iterable }
}
}
impl<'a, T: Value<'a>> Iterator for DataIterator<'a, T> {
type Item = &'a T;
fn next(&mut self) -> Option<Self::Item> {
match self.iterable.get(self.index) {
Some(item) => {
self.index += 1;
Some(item)
}
None => None,
}
}
}