From fddb3a79030aff8008dee05484e1d25dc78ac43c Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 28 Jul 2014 22:37:49 -0700 Subject: [PATCH] Implements the (mutable) index operator for vectors. Again, this is possibly an oversight. The operators simply use the mut_i() and i() methods which are demanded by the Array1 trait. This means you may access the field `x` on a VectorN with vector[0] syntax. Signed-off-by: Aaron Jacobs --- src/vector.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/vector.rs b/src/vector.rs index f5987eb..36f3e4b 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -215,6 +215,18 @@ macro_rules! vec( #[inline] fn one() -> $Self { $Self::from_value(one()) } } + impl Index for $Self { + #[inline] + fn index<'a>(&'a self, index: &uint) -> &'a S { + let slice: &[S, ..$n] = unsafe { mem::transmute(self) }; + &slice[*index] + } + } + + impl IndexMut for $Self { + #[inline] fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut S { self.mut_i(*index) } + } + impl ApproxEq for $Self { #[inline] fn approx_eq_eps(&self, other: &$Self, epsilon: &S) -> bool {