Fix to_ptr method impls

This commit is contained in:
Brendan Zabarauskas 2012-12-04 21:43:10 +10:00
parent a1fcfff9ed
commit 7e4a7e180b

View file

@ -149,17 +149,18 @@ pub impl<T> RGB<T>: Dimensional<T> {
pub impl<T:Copy> RGB<T>: Index<uint, T> { pub impl<T:Copy> RGB<T>: Index<uint, T> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> T { pure fn index(i: uint) -> T {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(self.to_ptr(), 3) |slice| { slice[i] } }
transmute::<*RGB<T>, *T>(
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
}
} }
} }
pub impl<T:Copy> RGB<T>: ToPtr<T> { pub impl<T:Copy> RGB<T>: ToPtr<T> {
#[inline(always)] #[inline(always)]
pure fn to_ptr(&self) -> *T { pure fn to_ptr(&self) -> *T {
ptr::to_unsafe_ptr(&self[0]) unsafe {
transmute::<*RGB<T>, *T>(
to_unsafe_ptr(&*self)
)
}
} }
} }
@ -272,17 +273,18 @@ pub impl<T> RGBA<T>: Dimensional<T> {
pub impl<T:Copy> RGBA<T>: Index<uint, T> { pub impl<T:Copy> RGBA<T>: Index<uint, T> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> T { pure fn index(i: uint) -> T {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[i] } }
transmute::<*RGBA<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
} }
} }
pub impl<T:Copy> RGBA<T>: ToPtr<T> { pub impl<T:Copy> RGBA<T>: ToPtr<T> {
#[inline(always)] #[inline(always)]
pure fn to_ptr(&self) -> *T { pure fn to_ptr(&self) -> *T {
ptr::to_unsafe_ptr(&self[0]) unsafe {
transmute::<*RGBA<T>, *T>(
to_unsafe_ptr(&*self)
)
}
} }
} }
@ -392,17 +394,18 @@ pub impl<T> HSV<T>: Dimensional<T> {
pub impl<T:Copy> HSV<T>: Index<uint, T> { pub impl<T:Copy> HSV<T>: Index<uint, T> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> T { pure fn index(i: uint) -> T {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(self.to_ptr(), 3) |slice| { slice[i] } }
transmute::<*HSV<T>, *T>(
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
}
} }
} }
pub impl<T:Copy> HSV<T>: ToPtr<T> { pub impl<T:Copy> HSV<T>: ToPtr<T> {
#[inline(always)] #[inline(always)]
pure fn to_ptr(&self) -> *T { pure fn to_ptr(&self) -> *T {
ptr::to_unsafe_ptr(&self[0]) unsafe {
transmute::<*HSV<T>, *T>(
to_unsafe_ptr(&*self)
)
}
} }
} }
@ -491,17 +494,18 @@ pub impl<T> HSVA<T>: Dimensional<T> {
pub impl<T:Copy> HSVA<T>: Index<uint, T> { pub impl<T:Copy> HSVA<T>: Index<uint, T> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> T { pure fn index(i: uint) -> T {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[i] } }
transmute::<*HSVA<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
} }
} }
pub impl<T:Copy> HSVA<T>: ToPtr<T> { pub impl<T:Copy> HSVA<T>: ToPtr<T> {
#[inline(always)] #[inline(always)]
pure fn to_ptr(&self) -> *T { pure fn to_ptr(&self) -> *T {
ptr::to_unsafe_ptr(&self[0]) unsafe {
transmute::<*HSVA<T>, *T>(
to_unsafe_ptr(&*self)
)
}
} }
} }