It's not necessary for U because there are no clones here, only moves.

On Thu, Oct 24, 2013 at 6:07 AM, Igor Bukanov <[email protected]> wrote:
> Here is the map example from the tutorial,
> http://static.rust-lang.org/doc/master/tutorial.html#generics ,
>
> fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
>     let mut accumulator = ~[];
>     for element in vector.iter() {
>         accumulator.push(function(element));
>     }
>     return accumulator;
> }
>
>
> It compiles even if the Clone trait is not specified for U and the
> push is defined as:
>
> fn push(&mut self, t: T);
>
> which I suppose implies a copy operation for T. So why the Clone trait
> is not necessary here for U?
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to