That code was a little jumbled and I can't answer your question or explain the details of this. But I was able to follow the suggestions of the compiler errors (which you didn't post, BTW) and eventually got it to compile and run:
In the code you posted, the compiler suggested specific changes. It doesn't always do this, but when it does it is worth trying them or at least thinking about them.
Do you read the compiler errors in your IDE, or on the command line when running cargo? I ask because some IDEs don't show the full error, so you'll miss the suggestions. If you're using vscode, be sure to click the link that says Click for full compiler diagnostic and you'll see the same thing that you would in the terminal.
Thank you very much for your suggestions.
You are right, I've missed the first compiler error.
However, your code doesn't work (edition 2021).
The tried to return an impl Iterator already before, but I got the same error as when I compile your code:
> rustc --edition 2021 scale-trait.rs
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in trait method return types
--> scale-trait.rs:12:34
|
12 | fn scale(self, factor: T) -> impl Iterator<Item = T> {
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
error: aborting due to previous error
For more information about this error, try `rustc --explain E0562`.
That was the reason I used Map<> as return type, but obviously I couldn't resolve the bounds correctly.
You are right again, a free function (or the simple use of the closure in main() would be easier here, but I try to form a trait for educational purposes.
And I think it is cleaner to remove the unnecessary bounds on T from the trait (avoiding repetition) and implement it for the bounds you need, allowing for the possibility of implementations with different bounds in the future: