4 ms·
I've found rust really helps out with this, enforcing some strict rules around types. I had to implement a `Lowercase` type which is just a string that can onl
by cetra3 6y ago
I've found rust really helps out with this, enforcing some strict rules around types.
I had to implement a `Lowercase` type which is just a string that can only be lowercase (for case insensitive searches). After implementing standard traits like `Into` and `Deref`, it just acted as a standard string. That way I could guarantee at compile time that things are lowercase, but still have the flexibility of strings.
Another common idiom I have seen is to compose finite state machines using enums. You can only create a particular state from another state etc..