format! builds a new String from its arguments. You can’t return an &str reference to it because the data will be deallocated when the function exits. If you’re returning anything other than literals, you’ll need your function to return String instead of &str.
That being said, some people may stumble upon this thread with more complex types than &str and String, and so there may not be such a convenient enum available to them.
In which case, the more general solution is to use:
That crate hasn't been yet fully released to the community yet, since I have yet to to release a guide / book for the crate to explain the motivation behind its design, and showcase some pretty neat usages we can do with it; but in the meantime it already works quite well.