Skip to content

Commit 5855d49

Browse files
Add array From impls for Vec2 and Vec3
Arrays are generally nicer to work with than tuples. For example they have a `map` method, unlike tuples. Add convenience From impls to ease interoperation with arrays.
1 parent b9cdb6d commit 5855d49

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/system/vector2.rs

+7
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ impl<T> From<(T, T)> for Vector2<T> {
274274
}
275275
}
276276

277+
impl<T> From<[T; 2]> for Vector2<T> {
278+
/// Constructs a `Vector2` from `[x, y]`.
279+
fn from([x, y]: [T; 2]) -> Self {
280+
Self { x, y }
281+
}
282+
}
283+
277284
/// Create a `Vector2` with both fields initialized to the same value
278285
impl<T: Clone> From<T> for Vector2<T> {
279286
fn from(src: T) -> Self {

src/system/vector3.rs

+7
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,10 @@ impl<T> From<(T, T, T)> for Vector3<T> {
473473
}
474474
}
475475
}
476+
477+
impl<T> From<[T; 3]> for Vector3<T> {
478+
/// Constructs a `Vector2` from `[x, y]`.
479+
fn from([x, y, z]: [T; 3]) -> Self {
480+
Self { x, y, z }
481+
}
482+
}

0 commit comments

Comments
 (0)