Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Cool and tricky
lol,
when i saw the task, i did not immediately think that all that is there, you can throw it away
r"^(\d{2}){2,3}$" :-)
I believe that the subtyping system of Rust will implicitly cast a type with a longer lifetime into a type with a shorter lifetime in order to satisfy a function signature.
Therefore, we only need the one lifetime generic
'a
in order to provide the same functionality as this solution, since parameters with a lifetime longer than'a
will be implicitly cast to have lifetime'a
.TIL about if-zero
Oh! Now I get it! At least, I think I do. What this is saying is that lifetimes 'a and 'b must each last at least as long as lifetime 'c.
My solution (well, the one I found on StackOverflow) was to just make all the lifetimes the same, 'a everywhere. But this one is clearly more correct.
The original source of the kata has 'c defined as 'a + 'b, which means 'c must last at least as long as the longer of 'a and 'b, but that's the opposite of what we want because we need 'c to last no longer than the shorter of 'a and 'b.
Thanks Heiss for this kata, and thanks to the users who posted this solution. I grok rust lifetimes much better now thanks to all of you!
Cute.
(%)
should not beinfixr
. function application is left associative.Clever - but I hat to read it twice :-)