<S: AsRef<str>> vs impl AsRef<str> #316
Replies: 2 comments 1 reply
-
I personally would say, that it's more an Any proposals for a name? |
Beta Was this translation helpful? Give feedback.
-
I can think in a difference between the two if used to define the function return type: A Generic is resolved into the real type based on the caller requirements. But the Eg: fn gen_iterator(value: u32) -> impl Iterator<Item = u32> {
0..value
}
fn main() {
let iterator = gen_iterator(2);
println!("result {:?}", iterator.collect::<Vec<u32>>())
} The Generic here don't work, because the fn gen_iterator<I: Iterator<Item = u32>>(value: u32) -> I {
0..value
} Even if you define the generic in the function call, the compiler will give you an error:
|
Beta Was this translation helpful? Give feedback.
-
I wasn't aware of the difference between
<S: AsRef<str>>
andimpl AsRef<str>
, original Q&A here. The answer from @jonhoo was:I wonder, how/where to include this here in the patterns repo, is this a pattern or an idiom, what name should it get?
Beta Was this translation helpful? Give feedback.
All reactions