Hacker News new | past | comments | ask | show | jobs | submit login

Thanks. I didn't want bitflags, this was just basically for an enumeration of channels/parameters e.g Foo=0, Bar=1, Baz=2. Ideally I'd like one that was numbered automatically and also offered a way of enumerating the possible values at runtime. I can't remember why I went back to constants in that case.

Another struggle I remember was just getting the max defined value. Again the Rust type is pretty Opaque because it hides the all-powerful discriminated union type. I love the Rust enum type, but I wish Rust also had a first-class dumb enum type, with all the C/C# niceties (bitflags, runtime enumeration, selection of backing field). This seems like quite a different from what the rust enum is.




You probably ran into this stuff not being built-in. You can add it on via a macro pretty easily, except that the "selection of backing field" is built in via the repr attribute. An example of this would be packages like https://docs.rs/enum_derive/0.1.7/enum_derive/

The other stuff isn't built in because it would add a bunch of code you may or may not want to your build, and it's easy enough to opt into. We also could solve that problem, in theory, a few ways, but there just hasn't been a ton of demand for it, so it hasn't been done.

With bitfields, there has been increasing demand lately, so we'll see.


I constantly run into the situation where you make 2 or more constants with a prefix. That always felt like a smell to me - but it might be because in C# it would be.

I'm talking about code that ends up looking like this: https://github.com/retep998/winapi-rs/blob/0.3/src/shared/nt...

You get type safety because you can define the type of constant rather than use some primitive, but there feels like something is something missing (nicer autocompletion, better auto generated documentation, and so on).


I would probably wrap constants with the same prefix in a module, but all that really does is make the naming feel nicer, I guess.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: