3 ms·
I would say UTF-8, but I really do miss old-school Pascal strings (aka strings with a length field and a fixed allocation) sometimes. Pascal strings could auto
by bsder 6y ago
I would say UTF-8, but I really do miss old-school Pascal strings (aka strings with a length field and a fixed allocation) sometimes.
Pascal strings could automatically #[derive] a whole bunch of the Rust traits (Copy, Clone, Send, Sync, Eq, PartialEq, ...) that would help sidestep a whole bunch of ownership issues when you start throwing strings around in Rust.
The downside would be that you would occasionally get a runtime panic!() if your strings overflowed.
Sometimes, I can live with that. Embedded in particular would mostly prefer Pascal strings.
I suspect that Rust is powerful enough to create a PString type like that and actually fit it into the language cleanly. The lifetime annotations may be the trickiest part (although--maybe not as everything is a fixed size).
- brundolf 6y ago> Pascal strings could automatically #[derive] a whole bunch of the Rust traits (Copy, Clone, Send, Sync, Eq, PartialEq, ...) Worth noting that the explicitness of #[derive] was a design decision; particularly when exposing a library API, it's good to have control over the set of interfaces you actually support, so that (for example) if one of them stops being derivable later you won't break people's code downstream
- selfhoster11 6y ago> The downside would be that you would occasionally get a runtime panic!() if your strings overflowed. VLQ/LEB128 would take care of encoding an arbitrary string size to avoid this issue.