Resolving `unstable_name_collisions` of an iterator

I have the following chain of iterator calls:

    pub fn to_usr_fmt(&self) -> String {
        self.into_iter()
            .map(|token| token.to_user_fmt())
            .intersperse("-")
            .collect()
    }

The intersperse iterator from itertools is generating a warning about a potential name collision with the std lib sometime in the future.

To fully qualify the function call (thus eliminating the possibility of a name collision) I tried a "quick and dirty" aliasing doing something like

let new_name = itertools::Itertools::intersperse;

However, for reasons likely obvious to many (not me in the moment), I received a typing error when I tried to use it in the chain of function calls.

Does anyone have any ideas for how to address the warning without losing the readability of the code?

You can use the method as described here; or add #[allow(unstable_name_collision)] to the method; or switch to .collect_vec().join("-").

2 Likes

Great (complete) answer. Thank you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.