Rust question: Is there an idiomatic way to create a type that acts like String but enforces some constraint on its contents (such as `[a-zA-Z_]*`)? I don't want to have to re-implement all the traits.
Conversation
There look to be a few RFCs to do with “newtypes” github.com/rust-lang/rfcs from a few years ago. Might help? ... cc
1
Yeah, sadly there’s nothing like that. It’s a tricky feature though. Like, it’s hard to anticipate what you would want to redefine and what you wouldn’t. And do those redefinitions preserve your invariants?


