Repository navigation
<S: AsRef<str>> vs impl AsRef<str> #316
wookietreiber
started this conversation in
Ideas
Replies: 2 comments 1 reply
|
I personally would say, that it's more an Any proposals for a name? |
1 reply
|
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: |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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?
All reactions