experiment with associated types some more
This commit is contained in:
parent
708b9bb341
commit
7db51e6d55
@ -94,7 +94,8 @@ macro_rules! dvec_impl(
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> Iterable<N> for $dvec<N> {
|
||||
impl<N> Iterable for $dvec<N> {
|
||||
type Output = N;
|
||||
#[inline]
|
||||
fn iter<'l>(&'l self) -> Iter<'l, N> {
|
||||
self.as_slice().iter()
|
||||
|
@ -190,7 +190,9 @@ macro_rules! absolute_impl(
|
||||
|
||||
macro_rules! iterable_impl(
|
||||
($t: ident, $dim: expr) => (
|
||||
impl<N> Iterable<N> for $t<N> {
|
||||
impl<N> Iterable for $t<N> {
|
||||
type Output = N;
|
||||
|
||||
#[inline]
|
||||
fn iter<'l>(&'l self) -> Iter<'l, N> {
|
||||
unsafe {
|
||||
|
@ -60,7 +60,9 @@ impl<N> Indexable<usize, N> for vec::Vec0<N> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: 'static> Iterable<N> for vec::Vec0<N> {
|
||||
impl<N: 'static> Iterable for vec::Vec0<N> {
|
||||
type Output = N;
|
||||
|
||||
#[inline]
|
||||
fn iter<'l>(&'l self) -> Iter<'l, N> {
|
||||
unsafe { mem::transmute::<&'l vec::Vec0<N>, &'l [N; 0]>(self).iter() }
|
||||
|
@ -243,7 +243,8 @@ macro_rules! new_repeat_impl(
|
||||
|
||||
macro_rules! iterable_impl(
|
||||
($t: ident, $dim: expr) => (
|
||||
impl<N> Iterable<N> for $t<N> {
|
||||
impl<N> Iterable for $t<N> {
|
||||
type Output = N;
|
||||
#[inline]
|
||||
fn iter<'l>(&'l self) -> Iter<'l, N> {
|
||||
unsafe {
|
||||
@ -504,6 +505,38 @@ macro_rules! dot_impl(
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! scalar_ops_impl(
|
||||
($t: ident, $($compN: ident),+) => (
|
||||
impl<N: Copy + Mul<N, Output = N>> ScalarMul<N> for $t<N> {
|
||||
#[inline]
|
||||
fn mul_s(&self, other: &N) -> $t<N> {
|
||||
$t::new($(self.$compN * *other),+)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Copy + Div<N, Output = N>> ScalarDiv<N> for $t<N> {
|
||||
#[inline]
|
||||
fn div_s(&self, other: &N) -> $t<N> {
|
||||
$t::new($(self.$compN / *other),+)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Copy + Add<N, Output = N>> ScalarAdd<N> for $t<N> {
|
||||
#[inline]
|
||||
fn add_s(&self, other: &N) -> $t<N> {
|
||||
$t::new($(self.$compN + *other),+)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Copy + Sub<N, Output = N>> ScalarSub<N> for $t<N> {
|
||||
#[inline]
|
||||
fn sub_s(&self, other: &N) -> $t<N> {
|
||||
$t::new($(self.$compN - *other),+)
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! translation_impl(
|
||||
($t: ident) => (
|
||||
impl<N: Copy + Add<N, Output = N> + Neg<Output = N>> Translation<$t<N>> for $t<N> {
|
||||
|
@ -59,12 +59,11 @@ pub trait Cast<T> {
|
||||
/// Trait of matrices.
|
||||
///
|
||||
/// A matrix has rows and columns and are able to multiply them.
|
||||
pub trait Mat<N, R, C: Mul<Self>>: Row<R> + Col<C> + Mul<R> + Index<(usize, usize), Output = N> { }
|
||||
pub trait Mat<N, R, C>: Row<R> + Col<C> + Index<(usize, usize), Output = N> { }
|
||||
|
||||
impl<N, M, R, C> Mat<N, R, C> for M
|
||||
where M: Row<R> + Col<C> + Mul<R> + Index<(usize, usize), Output = N>,
|
||||
C: Mul<M>,
|
||||
{}
|
||||
where M: Row<R> + Col<C> + Index<(usize, usize), Output = N> {
|
||||
}
|
||||
|
||||
/// Trait implemented by square matrices.
|
||||
pub trait SquareMat<N, V>: Mat<N, V, V> +
|
||||
@ -190,9 +189,11 @@ pub trait Indexable<I, N>: Shape<I> + IndexMut<I, Output = N> {
|
||||
/// This is a workaround of current Rust limitations.
|
||||
///
|
||||
/// Traits of objects which can be iterated through like a vector.
|
||||
pub trait Iterable<N> {
|
||||
pub trait Iterable {
|
||||
/// Iterable output type
|
||||
type Output;
|
||||
/// Gets a vector-like read-only iterator.
|
||||
fn iter<'l>(&'l self) -> Iter<'l, N>;
|
||||
fn iter<'l>(&'l self) -> Iter<'l, Self::Output>;
|
||||
}
|
||||
|
||||
/// This is a workaround of current Rust limitations.
|
||||
|
Loading…
Reference in New Issue
Block a user