std::iter::Iterator like type annotations in my crate (rust-analyzer)

I recently added rust-analyzer to my vim and realized how cool it is. In particular I like to see the type annotations that it adds when chaining methods, which turns out to be useful for example when using stuff from the Iterator trait:

let things: Vec<_> = (0..100) Range<i32>
    .map(|x| x.to_string()) impl Iterator<Item = String>
    .filter(|x| x.len() == 1) impl Iterator<Item = String>
    .map(|x| x.chars().next().unwrap()) impl Iterator<Item = char>
    .take(3) impl Iterator<Item = char>
    .collect();

(I had to paste the code instead of sharing a screenshot because as a new user I can only post one media item :confused: , but look at the type annotations on the right)

I wrote a crate (csvsc) that mimics this chaining behavior, using different structs to accomplish different tasks but implemented as a trait (RowStream) with a lot of methods, just like Iterator. But when I look at the type annotations that rust-analyzer gives me it has all the type parameters so after a few chained methods they don't even fit the screen:

So the question is, do ye know how can I get that nice impl RowStream type annotation? Is there a magic trick?

You currently can't. rust-analyzer specially looks for types from std::iter implementing Iterator to display them differently. Maybe it'd be worth opening a ticket in rust-analyzer for this though; it's worth thinking about how such things could be handled more nicely (I could imagine having an attribute to control this, for example).

(You can limit the size of your type hints using the rust-analyzer.inlayHints.maxLength setting, though.)

Thanks @fdiebold , I was hoping this wasn't a trick but something I could add (like the annotations you mentioned). Maybe it's time for me to dive into rust-analyzer's code and make a contribution :stuck_out_tongue: