Merge pull request #95 from bfops/master
FromIterator changes and phantom type annotations.
This commit is contained in:
commit
bfaab1bed5
@ -83,7 +83,6 @@ Feel free to add your project to this list if you happen to use **nalgebra**!
|
||||
#![deny(unused_results)]
|
||||
#![warn(missing_docs)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(hash)]
|
||||
#![feature(core)]
|
||||
#![feature(std_misc)]
|
||||
#![doc(html_root_url = "http://nalgebra.org/doc")]
|
||||
|
@ -3,7 +3,7 @@
|
||||
#![allow(missing_docs)] // we hide doc to not have to document the $trhs double dispatch trait.
|
||||
|
||||
use std::slice::{Iter, IterMut};
|
||||
use std::iter::FromIterator;
|
||||
use std::iter::{FromIterator, IntoIterator};
|
||||
use std::iter::repeat;
|
||||
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
|
||||
use rand::{self, Rand};
|
||||
@ -68,8 +68,8 @@ impl<N> DVec<N> {
|
||||
|
||||
impl<N> FromIterator<N> for DVec<N> {
|
||||
#[inline]
|
||||
fn from_iter<I: Iterator<Item = N>>(param: I) -> DVec<N> {
|
||||
DVec { at: param.collect() }
|
||||
fn from_iter<I: IntoIterator<Item = N>>(param: I) -> DVec<N> {
|
||||
DVec { at: param.into_iter().collect() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -497,12 +497,12 @@ macro_rules! small_dvec_from_impl (
|
||||
|
||||
impl<N: Zero> FromIterator<N> for $dvec<N> {
|
||||
#[inline]
|
||||
fn from_iter<I: Iterator<Item = N>>(param: I) -> $dvec<N> {
|
||||
fn from_iter<I: IntoIterator<Item = N>>(param: I) -> $dvec<N> {
|
||||
let mut at: [N; $dim] = [ $( $zeros, )* ];
|
||||
|
||||
let mut dim = 0;
|
||||
|
||||
for n in param {
|
||||
for n in param.into_iter() {
|
||||
if dim == $dim {
|
||||
break;
|
||||
}
|
||||
|
@ -2,9 +2,10 @@
|
||||
|
||||
#![allow(missing_docs)] // we allow missing to avoid having to document the point components.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::slice::{Iter, IterMut};
|
||||
use std::iter::{Iterator, FromIterator};
|
||||
use std::iter::{Iterator, FromIterator, IntoIterator};
|
||||
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
|
||||
use rand::{Rand, Rng};
|
||||
use traits::operations::{ApproxEq, POrd, POrdering, Axpy, ScalarAdd, ScalarSub, ScalarMul,
|
||||
@ -18,20 +19,20 @@ use quickcheck::{Arbitrary, Gen};
|
||||
|
||||
|
||||
/// Point of dimension 0.
|
||||
#[derive(Eq, PartialEq, RustcDecodable, Clone, Debug, Copy)]
|
||||
pub struct Pnt0<N>;
|
||||
#[derive(Eq, PartialEq, Clone, Debug, Copy)]
|
||||
pub struct Pnt0<N>(pub PhantomData<N>);
|
||||
|
||||
impl<N> Pnt0<N> {
|
||||
/// Creates a new point.
|
||||
#[inline]
|
||||
pub fn new() -> Pnt0<N> {
|
||||
Pnt0
|
||||
Pnt0(PhantomData)
|
||||
}
|
||||
|
||||
/// Creates a new point. The parameter is not taken in account.
|
||||
#[inline]
|
||||
pub fn new_repeat(_: N) -> Pnt0<N> {
|
||||
Pnt0
|
||||
Pnt0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use std::mem;
|
||||
use std::num;
|
||||
use std::slice::{Iter, IterMut};
|
||||
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
|
||||
use std::iter::FromIterator;
|
||||
use std::iter::{FromIterator, IntoIterator};
|
||||
use rand::{Rand, Rng};
|
||||
use structs::{Vec3, Pnt3, Rot3, Mat3};
|
||||
use traits::operations::{ApproxEq, Inv, POrd, POrdering, Axpy, ScalarAdd, ScalarSub, ScalarMul,
|
||||
|
@ -1,7 +1,8 @@
|
||||
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::slice::{Iter, IterMut};
|
||||
use std::iter::{Iterator, FromIterator};
|
||||
use std::iter::{FromIterator, IntoIterator};
|
||||
use rand::{Rand, Rng};
|
||||
use traits::operations::ApproxEq;
|
||||
use traits::structure::{Iterable, IterableMut, Indexable, Basis, Dim, Shape, BaseFloat, BaseNum,
|
||||
@ -12,7 +13,7 @@ use structs::vec;
|
||||
impl<N> Zero for vec::Vec0<N> {
|
||||
#[inline]
|
||||
fn zero() -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -107,7 +108,7 @@ impl<N, T> Add<T> for vec::Vec0<N> {
|
||||
|
||||
#[inline]
|
||||
fn add(self, _: T) -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +117,7 @@ impl<N, T> Sub<T> for vec::Vec0<N> {
|
||||
|
||||
#[inline]
|
||||
fn sub(self, _: T) -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +126,7 @@ impl<N: Neg<Output = N> + Copy> Neg for vec::Vec0<N> {
|
||||
|
||||
#[inline]
|
||||
fn neg(self) -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +142,7 @@ impl<N, T> Mul<T> for vec::Vec0<N> {
|
||||
|
||||
#[inline]
|
||||
fn mul(self, _: T) -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +151,7 @@ impl<N, T> Div<T> for vec::Vec0<N> {
|
||||
|
||||
#[inline]
|
||||
fn div(self, _: T) -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,30 +237,30 @@ impl<N: ApproxEq<N>> ApproxEq<N> for vec::Vec0<N> {
|
||||
impl<N: One> One for vec::Vec0<N> {
|
||||
#[inline]
|
||||
fn one() -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> FromIterator<N> for vec::Vec0<N> {
|
||||
#[inline]
|
||||
fn from_iter<I: Iterator<Item = N>>(_: I) -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
fn from_iter<I: IntoIterator<Item = N>>(_: I) -> vec::Vec0<N> {
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Bounded> Bounded for vec::Vec0<N> {
|
||||
#[inline]
|
||||
fn max_value() -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn min_value() -> vec::Vec0<N> {
|
||||
vec::Vec0
|
||||
vec::Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> Rand for vec::Vec0<N> {
|
||||
#[inline]
|
||||
fn rand<R: Rng>(_: &mut R) -> vec::Vec0<N> { vec::Vec0 }
|
||||
fn rand<R: Rng>(_: &mut R) -> vec::Vec0<N> { vec::Vec0(PhantomData) }
|
||||
}
|
||||
|
@ -3,9 +3,10 @@
|
||||
#![allow(missing_docs)] // we allow missing to avoid having to document the dispatch traits.
|
||||
|
||||
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::slice::{Iter, IterMut};
|
||||
use std::iter::{Iterator, FromIterator};
|
||||
use std::iter::{Iterator, FromIterator, IntoIterator};
|
||||
use rand::{Rand, Rng};
|
||||
use traits::operations::{ApproxEq, POrd, POrdering, Axpy, ScalarAdd, ScalarSub, ScalarMul,
|
||||
ScalarDiv, Absolute};
|
||||
@ -20,20 +21,20 @@ use quickcheck::{Arbitrary, Gen};
|
||||
|
||||
|
||||
/// Vector of dimension 0.
|
||||
#[derive(Eq, PartialEq, RustcDecodable, Clone, Debug, Copy)]
|
||||
pub struct Vec0<N>;
|
||||
#[derive(Eq, PartialEq, Clone, Debug, Copy)]
|
||||
pub struct Vec0<N>(pub PhantomData<N>);
|
||||
|
||||
impl<N> Vec0<N> {
|
||||
/// Creates a new vector.
|
||||
#[inline]
|
||||
pub fn new() -> Vec0<N> {
|
||||
Vec0
|
||||
Vec0(PhantomData)
|
||||
}
|
||||
|
||||
/// Creates a new vector. The parameter is not taken in account.
|
||||
#[inline]
|
||||
pub fn new_repeat(_: N) -> Vec0<N> {
|
||||
Vec0
|
||||
Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -680,7 +680,8 @@ macro_rules! from_iterator_impl(
|
||||
($t: ident, $param0: ident) => (
|
||||
impl<N> FromIterator<N> for $t<N> {
|
||||
#[inline]
|
||||
fn from_iter<I: Iterator<Item = N>>(mut $param0: I) -> $t<N> {
|
||||
fn from_iter<I: IntoIterator<Item = N>>($param0: I) -> $t<N> {
|
||||
let mut $param0 = $param0.into_iter();
|
||||
$t::new($param0.next().unwrap())
|
||||
}
|
||||
}
|
||||
@ -688,7 +689,8 @@ macro_rules! from_iterator_impl(
|
||||
($t: ident, $param0: ident, $($paramN: ident),+) => (
|
||||
impl<N> FromIterator<N> for $t<N> {
|
||||
#[inline]
|
||||
fn from_iter<I: Iterator<Item = N>>(mut $param0: I) -> $t<N> {
|
||||
fn from_iter<I: IntoIterator<Item = N>>($param0: I) -> $t<N> {
|
||||
let mut $param0 = $param0.into_iter();
|
||||
$t::new($param0.next().unwrap(),
|
||||
$($paramN.next().unwrap()),+)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user