Add unchecked access to vector components on the Indexable trait.
This commit is contained in:
parent
15d12e5322
commit
1e71dc1d0a
|
@ -192,6 +192,16 @@ macro_rules! indexable_impl(
|
|||
.swap(i1 + j1 * $dim, i2 + j2 * $dim)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn unsafe_at(&self, (i, j): (uint, uint)) -> N {
|
||||
(*cast::transmute::<&$t<N>, &[N, ..$dim * $dim]>(self).unsafe_ref(i + j * $dim)).clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn unsafe_set(&mut self, (i, j): (uint, uint), val: N) {
|
||||
(*cast::transmute::<&mut $t<N>, &mut [N, ..$dim * $dim]>(self).unsafe_mut_ref(i + j * $dim)) = val
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -23,12 +23,19 @@ impl<N> Indexable<uint, N> for vec::Vec0<N> {
|
|||
|
||||
#[inline]
|
||||
fn set(&mut self, _: uint, _: N) {
|
||||
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn swap(&mut self, _: uint, _: uint) {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn unsafe_at(&self, _: uint) -> N {
|
||||
fail!("Cannot index a Vec0.")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn unsafe_set(&mut self, _: uint, _: N) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -144,6 +144,16 @@ macro_rules! indexable_impl(
|
|||
cast::transmute::<&mut $t<N>, &mut [N, ..$dim]>(self).swap(i1, i2)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn unsafe_at(&self, i: uint) -> N {
|
||||
(*cast::transmute::<&$t<N>, &[N, ..$dim]>(self).unsafe_ref(i)).clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn unsafe_set(&mut self, i: uint, val: N) {
|
||||
(*cast::transmute::<&mut $t<N>, &mut [N, ..$dim]>(self).unsafe_mut_ref(i)) = val
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -113,6 +113,15 @@ pub trait Indexable<Index, Res> {
|
|||
fn set(&mut self, i: Index, Res);
|
||||
/// Swaps the `i`-th element of `self` with its `j`-th element.
|
||||
fn swap(&mut self, i: Index, j: Index);
|
||||
|
||||
/// Reads the `i`-th element of `self`.
|
||||
///
|
||||
/// `i` is not checked.
|
||||
unsafe fn unsafe_at(&self, i: Index) -> Res;
|
||||
/// Writes to the `i`-th element of `self`.
|
||||
///
|
||||
/// `i` is not checked.
|
||||
unsafe fn unsafe_set(&mut self, i: Index, Res);
|
||||
}
|
||||
|
||||
/// This is a workaround of current Rust limitations.
|
||||
|
|
Loading…
Reference in New Issue