diff --git a/src/point.rs b/src/point.rs index c263f5c..c659293 100644 --- a/src/point.rs +++ b/src/point.rs @@ -103,6 +103,11 @@ macro_rules! impl_point { impl Array for $PointN { type Element = S; + #[inline] + fn len() -> usize { + $n + } + #[inline] fn from_value(scalar: S) -> $PointN { $PointN { $($field: scalar),+ } diff --git a/src/structure.rs b/src/structure.rs index 49c271c..6c36cc0 100644 --- a/src/structure.rs +++ b/src/structure.rs @@ -35,6 +35,16 @@ pub trait Array where { type Element: Copy; + /// Get the number of elements in the array type + /// + /// ```rust + /// use cgmath::prelude::*; + /// use cgmath::Vector3; + /// + /// assert_eq!(Vector3::::len(), 3); + /// ``` + fn len() -> usize; + /// Construct a vector from a single value, replicating it. /// /// ```rust diff --git a/src/vector.rs b/src/vector.rs index 7b70a72..0a2214f 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -129,6 +129,11 @@ macro_rules! impl_vector { impl Array for $VectorN { type Element = S; + #[inline] + fn len() -> usize { + $n + } + #[inline] fn from_value(scalar: S) -> $VectorN { $VectorN { $($field: scalar),+ }