If you try to do the same mistake in Rust it does not compile, this function takes an int (obviously shouldn't but that's a different design bug in C not C++) and we have a wchat_t which is not an int, so that does not compile at all. Footgun removed.
When you start trying to figure out how to write the equivalent mistake in Rust properly, you discover that Rust says uppercasing or lowercasing arbitrary Unicode char values gets you an Iterator and you can't convince your compiler that this cannot make the string longer -- because in fact it might make the string longer. The mistake is averted by design.
There's nothing converting the case of a string in place. The iterator does not decide how many bytes the string has, it delivers one character at a time. It's trivial to decide how many bytes a character has (it's on the definition of your encoding), and it's written down at the type definition.
Converting the case of an string in place is just a bad operation. It should not be done. So the Rust stdlib doesn't do it. The idea that complexity has a fixed size is trivially wrong.
The Iterator doesn't have bytes in it, we're not idiots, the Iterator is over Rust's char type, a Unicode scalar value (a "character" if you don't know the lingo)
What's delivering value here is division of responsibility. Cutting a problem up into pieces each of which can be tackled by an expert. Uppercasing text, encoding characters as bytes, allocating memory, appending to a buffer, these are all distinct problems which a different expert can solve properly.
In that Ruby code you need to gather maybe a half dozen experts to agree how to write this function. Or, of course, one expert YOLOs the rest of it because every topic we don't know much about is easy, right...
Rust does this division a lot. You as a programmer see String but when your String grows that's not code in String where people who know about Unicode live, that's RawVecInner<A> and that code doesn't even know about characters or strings or any such thing, it just allocates enough space to store data.