简体   繁体   中英

Rust constraints for generic types Item

While looking through the documentation for flatten .

pub struct Flatten<I> 
where
    I: Iterator,
    <I as Iterator>::Item: IntoIterator, 

I was wondering why this is needed -- the last line. Would the following not be sufficient?

I::Item: IntoIterator,

After all I is constrained to be Iterator on the line before.

This is not necessary, indeed, and the actual code uses completely another form (an unstable Trait<Assoc: Trait> syntax, similar to the equality syntax Trait<Assoc = Type> ). It is just rustdoc showing that, because in theory you could have a type parameter implementing two traits that both have the same associated item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM