From 13a5bee25f1e6556be98bea3e051342bb4f63b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 19 Apr 2016 09:34:44 +0200 Subject: [PATCH] Implement From returning a value (instead of a ref only) for matrices and vectors. --- src/structs/matrix_macros.rs | 8 ++++++++ src/structs/vector_macros.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/structs/matrix_macros.rs b/src/structs/matrix_macros.rs index 6bbd0aa8..3c401c6b 100644 --- a/src/structs/matrix_macros.rs +++ b/src/structs/matrix_macros.rs @@ -50,6 +50,14 @@ macro_rules! conversion_impl( } } } + + impl<'a, N: Clone> From<&'a [[N; $dimension]; $dimension]> for $t { + #[inline] + fn from(arr: &'a [[N; $dimension]; $dimension]) -> $t { + let tref: &$t = From::from(arr); + tref.clone() + } + } ) ); diff --git a/src/structs/vector_macros.rs b/src/structs/vector_macros.rs index 99c6e980..6f52b342 100644 --- a/src/structs/vector_macros.rs +++ b/src/structs/vector_macros.rs @@ -51,6 +51,14 @@ macro_rules! conversion_impl( } } } + + impl<'a, N: Clone> From<&'a [N; $dimension]> for $t { + #[inline] + fn from(arr: &'a [N; $dimension]) -> $t { + let vref: &$t = From::from(arr); + vref.clone() + } + } ) );