Add with_iterator to TypeBuilder.

This commit is contained in:
Stephen Chung
2022-08-09 18:18:41 +08:00
parent f323644e20
commit 8408c190dc
3 changed files with 71 additions and 23 deletions

View File

@@ -45,11 +45,21 @@ fn build_type() -> Result<(), Box<EvalAltResult>> {
}
}
impl IntoIterator for Vec3 {
type Item = INT;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
vec![self.x, self.y, self.z].into_iter()
}
}
impl CustomType for Vec3 {
fn build(mut builder: TypeBuilder<Self>) {
builder
.with_name("Vec3")
.with_fn("vec3", Self::new)
.with_iterator()
.with_get_set("x", Self::get_x, Self::set_x)
.with_get_set("y", Self::get_y, Self::set_y)
.with_get_set("z", Self::get_z, Self::set_z);