3 ms·
I think Rust solves a lot of these problems. > Calculating the size of a static array some_array.len() > Getting the maximum value of an enum Rust's enums a
by LambdaComplex 9y ago
I think Rust solves a lot of these problems.
> Calculating the size of a static array
some_array.len()
> Getting the maximum value of an enum
Rust's enums are strongly-typed (I think that's the right phrase), so this is a non-issue.
> Converting an enum to a string
impl Display for MyEnum (and then call to_string() on it)
> Converting a string to an enum
This could be tricky, since Rust enum variants can contain data. But if none of the variants contain data, it would be easy to make a method that returns a Result<MyEnum, CustomParseError>
> Binary file includes
include_bytes! macro (or the include_str! macro, depending on the exact scenario)
> Switch/case is still stupid
Pretty sure Rust's match is a lot better
- pcwalton 9y ago> This could be tricky, since Rust enum variants can contain data. But if none of the variants contain data, it would be easy to make a method that returns a Result<MyEnum, CustomParseError> Usually when you want to convert a string to an enum, you're trying to build some kind of parser or deserialization library, in which nom or serde are the best choices. (Of course, C++ has several parser frameworks too.)
- LambdaComplex 9y agoYeah, I would definitely be using serde in that case