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