▲ 109 ▼ Stop writing CLI validation. Parse it right the first time. (hackers.pub) submitted 11 months ago by hongminhee@lemmy.ml to c/programming@programming.dev 18 comments fedilink hide all child comments
[–] TehPers@beehaw.org 7 points 11 months ago (1 child) Mentioned this to the other commenter, but this doesn't use the type system to enforce the mutual exclusivity constraint. In Rust, the main way to do that via the type system is through enums. permalink fedilink source parent hideshow 2 child comments replies: [–] Ephera@lemmy.ml 3 points 11 months ago Ah, fair enough. Not sure how to do that then. I was gonna say, I feel like the current method does a good enough job documenting that validation has happened, but I guess you do want it reflected in the structure of the type, so that the code that takes the information from the struct can safely make the assumption that some of the options don't exist. And then, yeah, it would be nice to not need a separate parsing step for that. permalink fedilink source parent
[–] Ephera@lemmy.ml 3 points 11 months ago Ah, fair enough. Not sure how to do that then. I was gonna say, I feel like the current method does a good enough job documenting that validation has happened, but I guess you do want it reflected in the structure of the type, so that the code that takes the information from the struct can safely make the assumption that some of the options don't exist. And then, yeah, it would be nice to not need a separate parsing step for that. permalink fedilink source parent