Add size_of static method
This commit is contained in:
parent
7ce41e6e9e
commit
af2ca2be45
4 changed files with 26 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
use core::cmp::Eq;
|
||||
|
||||
pub trait Dimensional<T>: Index<uint, T> {
|
||||
static pure fn dim() -> uint;
|
||||
static pure fn dim() -> uint; // dim and size_of are pretty useless at the moment due to
|
||||
static pure fn size_of() -> uint; // how Rust's static methods are currently implemented
|
||||
pure fn to_ptr() -> *T;
|
||||
}
|
10
src/mat.rs
10
src/mat.rs
|
@ -1,6 +1,7 @@
|
|||
use core::cast::transmute;
|
||||
use core::cmp::{Eq, Ord};
|
||||
use core::ptr::to_unsafe_ptr;
|
||||
use core::sys::size_of;
|
||||
use core::vec::raw::buf_as_slice;
|
||||
|
||||
use std::cmp::FuzzyEq;
|
||||
|
@ -172,6 +173,9 @@ pub impl<T:Copy> Mat2<T>: Matrix<T, Vec2<T>, Vec2<T>> {
|
|||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 2 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Mat2<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn rows() -> uint { 2 }
|
||||
|
||||
|
@ -408,6 +412,9 @@ pub impl<T:Copy> Mat3<T>: Matrix<T, Vec3<T>, Vec3<T>> {
|
|||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 3 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Mat3<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn rows() -> uint { 3 }
|
||||
|
||||
|
@ -722,6 +729,9 @@ pub impl<T:Copy> Mat4<T>: Matrix<T, Vec4<T>, Vec4<T>> {
|
|||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 4 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Mat4<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn rows() -> uint { 4 }
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use core::cast::transmute;
|
||||
use core::cmp::{Eq, Ord};
|
||||
use core::ptr::to_unsafe_ptr;
|
||||
use core::sys::size_of;
|
||||
use core::vec::raw::buf_as_slice;
|
||||
|
||||
use std::cmp::FuzzyEq;
|
||||
|
@ -89,6 +90,9 @@ pub impl<T:Copy Num NumCast Trig Exp Clamp Ord AngleConv> Quat<T>: Quaternion<T>
|
|||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 4 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Quat<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr() -> *T {
|
||||
to_unsafe_ptr(&self[0])
|
||||
|
|
10
src/vec.rs
10
src/vec.rs
|
@ -1,6 +1,7 @@
|
|||
use core::cast::transmute;
|
||||
use core::cmp::Eq;
|
||||
use core::ptr::to_unsafe_ptr;
|
||||
use core::sys::size_of;
|
||||
use core::vec::raw::buf_as_slice;
|
||||
|
||||
use std::cmp::FuzzyEq;
|
||||
|
@ -108,6 +109,9 @@ pub impl<T:Copy> Vec2<T>: Vector<T> {
|
|||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 2 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Vec2<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> T {
|
||||
unsafe { do buf_as_slice(
|
||||
|
@ -259,6 +263,9 @@ pub impl<T:Copy> Vec3<T>: Vector<T> {
|
|||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 3 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Vec3<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> T {
|
||||
unsafe { do buf_as_slice(
|
||||
|
@ -428,6 +435,9 @@ pub impl<T:Copy> Vec4<T>: Vector<T> {
|
|||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 4 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Vec4<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> T {
|
||||
unsafe { do buf_as_slice(
|
||||
|
|
Loading…
Reference in a new issue