From 151c6c6e64be4799616152230b6127dbc8a5e371 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 6 May 2015 10:32:09 +0200 Subject: [PATCH] Replace as_matrix* by impl AsRef { mat: Matrix2 } -impl Basis2 { - /// Coerce to a `Matrix2` +impl AsRef> for Basis2 { #[inline] - pub fn as_matrix2<'a>(&'a self) -> &'a Matrix2 { &self.mat } + fn as_ref(&self) -> &Matrix2 { + &self.mat + } } /// Represents types which can be converted to a rotation matrix. @@ -251,10 +252,13 @@ impl Basis3 { pub fn from_quaternion(quaternion: &Quaternion) -> Basis3 { Basis3 { mat: quaternion.clone().into() } } +} - /// Coerce to a `Matrix3` +impl AsRef> for Basis3 { #[inline] - pub fn as_matrix3<'a>(&'a self) -> &'a Matrix3 { &self.mat } + fn as_ref(&self) -> &Matrix3 { + &self.mat + } } /// Represents types which can be converted to a rotation matrix. diff --git a/tests/rotation.rs b/tests/rotation.rs index 5acc26e..4ee31de 100644 --- a/tests/rotation.rs +++ b/tests/rotation.rs @@ -33,11 +33,15 @@ mod rotation { #[test] fn test_invert_basis2() { let a: Basis2<_> = rotation::a2(); - assert!(a.concat(&a.invert()).as_matrix2().is_identity()); + let a = a.concat(&a.invert()); + let a: &Matrix2<_> = a.as_ref(); + assert!(a.is_identity()); } #[test] fn test_invert_basis3() { let a: Basis3<_> = rotation::a3(); - assert!(a.concat(&a.invert()).as_matrix3().is_identity()); + let a = a.concat(&a.invert()); + let a: &Matrix3<_> = a.as_ref(); + assert!(a.is_identity()); }