A dynamic-sized local variable is a compiler error.Ī fixed-size array (where the size is part of the type) can be a local variable. Dynamic-sized types must be heap-allocated, and hidden behind a reference (the reference itself has fixed size). This is an integral part of the language semantics: local variables are stack-allocated and must have fixed size. Part of Rust's memory discipline is whether a value's size in memory is known at compile time or not. They tend to assume values go on the Heap, and treat stack-allocation as a compiler optimization. Rust is more explicit about memory manipulation and memory lay-out than many other languages, including the ones you listed. (I only realized after posting that this came across as a retort, which wasn't quite how I intended it.) Once you go outside the realm of ASCII, strings become a lot more nuanced and treating them as an "array of characters" is almost always incorrect. I'm mostly just expanding on what you already said: So although utf8 may have started as what seemed like a hacky solution to a hairy problem, it's actually an excellent, very well engineered text encoding.Įdit: and just to clarify, I'm not disagreeing with you here in general. So in other words, utf8 being variable length doesn't really add much complexity in practice because Unicode is always variable length anyway-regardless of encoding-due to grapheme clusters.Īnd on top of that, utf8 completely eliminates the question of endianness because it's a byte-oriented encoding, whereas utf16 and utf32 both require a byte order marking at the start of a document to indicate its endianess, and correspondingly need separate code paths to handle each case. So even with a & you can still accidentally index into the middle of something that should be treated as a single displayable character. What we think of as written characters are actually often represented with a series of multiple chars. get the 8th character of a string by just grabbing 8th element, because utf8 encodes characters with variable length.īut what a lot of people don't realize is that in practice that's actually true of utf32 (i.e. The main frustration most people have with utf8 is that they can't e.g. It's actually just hands down the best encoding for Unicode text. And IMO it's so elegant and well designed that, in practice, it doesn't end up being a hack at all. As Tom Scott himself emphasizes in that video (assuming we're talking about the same one) it's an extraordinarily elegant hack. Tom Scott has a wonderful rant on YouTube about Unicode and how UTF-8 is actually a giant hack We'll do our best to keep these links up to date, but if we fall behind please don't hesitate to shoot us a modmail. This is not an official Rust forum, and cannot fulfill feature requests. Err on the side of giving others the benefit of the doubt.Īvoid re-treading topics that have been long-settled or utterly exhausted. Please create a read-only mirror and link that instead.Ī programming language is rarely worth getting worked up over.īe charitable in intent. If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Post titles should include useful context.įor Rust questions, use the stickied Q&A thread.Īrts-and-crafts posts are permitted on weekends.Ĭriticism is encouraged, though it must be constructive, useful and actionable. For content that does not, use a text post to explain its relevance. Posts must reference Rust or relate to things using Rust. We observe the Rust Project Code of Conduct. Strive to treat others with respect, patience, kindness, and empathy. Please read The Rust Community Code of Conduct The Rust Programming LanguageĪ place for all things related to the Rust programming language-an open-source systems language that emphasizes performance, reliability, and productivity.
0 Comments
Leave a Reply. |