You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::iterator::*;fnmain(){let _xs = Counter::new(0,1).take_while(|&x| x < 20).to_vec();}
However, take and drop run into a type inference bug:
use std::iterator::*;fnmain(){let _xs = Counter::new(0,1).take(20).to_vec();}
bar.rs:4:14: 4:51 error: cannot determine a type for this bounded type parameter: unconstrained type
bar.rs:4 let _xs = Counter::new(0, 1).take(20).to_vec();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The definitions of TakeIterator and TakeWhileIterator are similar, but TakeIterator is only parameterized by T (the type of the contained Iterator) while TakeWhileIterator also has an A parameter (the type of the yielded element).
It seems the type of the element A is unable to be inferred from T, where T is an Iterator<A>.
/// An iterator which only iterates over the first `n` iterations of `iter`.pubstructTakeIterator<T>{
priv iter:T,priv n:uint}impl<A,T:Iterator<A>>Iterator<A>forTakeIterator<T>{#[inline]fnnext(&mutself) -> Option<A>{let next = self.iter.next();ifself.n != 0{self.n -= 1;
next
}else{None}}}
The text was updated successfully, but these errors were encountered:
huonw
added a commit
to huonw/rust
that referenced
this issue
Jun 6, 2013
I have also hit this problem, but in my case, I end up needing to use four dummy type parameters and still needed to provide a hint when called. This is not tenable as a usable API.
I'm going to nominate this. I'm not sure what for, I'm thinking well-covered as this limits how complex you can feasibly make your types (not very, it turns out).
The following works (as does
drop_while
):However,
take
anddrop
run into a type inference bug:The definitions of
TakeIterator
andTakeWhileIterator
are similar, butTakeIterator
is only parameterized byT
(the type of the containedIterator
) whileTakeWhileIterator
also has anA
parameter (the type of the yielded element).It seems the type of the element
A
is unable to be inferred fromT
, whereT
is anIterator<A>
.The text was updated successfully, but these errors were encountered: