Use explicit range when slicing into string #2664
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I don't like the
&s2[s2.len() - s1.len()..]
index operation because it's always hard for me to scan and explain, and I don't want to be focusing on the math, I want to focus on the slice operation. I think it would be better to use an explicit range so we can keep things simple and clear for students. I also never liked thats3
is "World", since that's also whats1
was, so I don't feel it clearly enough demonstrates thats3
is coming froms2
. I think pulling a weird range out of the middle ofs2
would better show that we're indeed looking at part of the full string. Nows3
is "llo Wor".