Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the logic errors pattern
The wrong operator, an inverted condition, a formula the right way round but backwards.
What went wrong: In Rust, string slicing s[0..2] operates on byte offsets, not Unicode scalar values. The emoji '🦀' spans 4 UTF-8 bytes (0..4). Slicing at byte index 2 lands inside the character, triggering a runtime panic.
The fix: Use s.chars().take(2).collect() to slice by Unicode character count rather than byte offsets.
Remember: Rust strings are UTF-8 encoded. Direct byte slicing panics unless the index is guaranteed to be on a character boundary.
The pattern behind it: logic errors.
Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.
<iframe src="https://trybughunt.com/embed/cc680255-ac36-4188-81f0-5551c005cdda" title="Debugging challenge: UTF-8 byte index is not a char boundary panic" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/cc680255-ac36-4188-81f0-5551c005cdda">TryBugHunt</a></p>