How to constrain the element type of an iterator?

前端 未结 3 1376
离开以前
离开以前 2021-01-19 04:15

I’m converting some older Rust code to work on 1.0.0. I need to convert a function that takes an iterator over characters, which used to be written like this:



        
3条回答
  •  耶瑟儿~
    2021-01-19 04:36

    Okay, I was able to figure this out from reading some RFC discussions, and the answer is that you can instantiate associated types in the trait (like signature fibration in ML):

    fn f>(char_iter: I)
    

    Soon it should be possible to use equality constraints in where clauses, but this doesn’t work in 1.0.0-alpha:

    fn f(char_iter: I) where I::Item == char
    

提交回复
热议问题