My initial confusion started when I looked at this code:
http://exercism.io/submissions/e3e0acc3148b4f42aed494485ccd0bb8
Specifically this bit
.collect::<String>() {
ref s if s.is_empty() => return num.to_string(),
s => s,
}
This syntax of having a scope (?) after the string function was new to me. So I checked out the documentation of collect to see if there were examples. Becuase to me (as a rubyist) this looks like we're passing a block to collect. Though that's probably not what's going on.
Anyway, the collect
documentation doesn't show any examples like this. But the
iterator trait list does show this weird (to me) {...}
syntax after each
function
fn collect<B>(self) -> B where B: FromIterator<Self::Item> { ... }
So I figured that the syntax that confused me and this { ... }
were related. But I couldn't find any documentation about what is
going on here.
So...what's going on here. And is there a place in the book where we could document this sort of thing?
Related, what is the ref
keyword in the code sample? That is something else I looked for in the book and the API documentation
and had no luck.