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<S> trait. This means you may access the field `x` on a VectorN with vector[0] syntax. Signed-off-by: Aaron Jacobs <atheriel@gmail.com>
This commit is contained in:
parent
7e81b258a9
commit
fddb3a7903
1 changed files with 12 additions and 0 deletions
|
@ -215,6 +215,18 @@ macro_rules! vec(
|
|||
#[inline] fn one() -> $Self<S> { $Self::from_value(one()) }
|
||||
}
|
||||
|
||||
impl<S: BaseNum> Index<uint, S> for $Self<S> {
|
||||
#[inline]
|
||||
fn index<'a>(&'a self, index: &uint) -> &'a S {
|
||||
let slice: &[S, ..$n] = unsafe { mem::transmute(self) };
|
||||
&slice[*index]
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: BaseNum> IndexMut<uint, S> for $Self<S> {
|
||||
#[inline] fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut S { self.mut_i(*index) }
|
||||
}
|
||||
|
||||
impl<S: BaseFloat> ApproxEq<S> for $Self<S> {
|
||||
#[inline]
|
||||
fn approx_eq_eps(&self, other: &$Self<S>, epsilon: &S) -> bool {
|
||||
|
|
Loading…
Reference in a new issue