Here is an allocation-free, more idiomatic, and more generic version, which doesn't crash on incorrectly-formatted keys.