this post was submitted on 06 Sep 2025
109 points (95.0% liked)

Programming

22755 readers
24 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] TehPers@beehaw.org 3 points 2 weeks ago (2 children)

I like the concept, and it's great in TS. Unfortunately, not as doable in other languages.

I'm a bit curious if it's possible to extend clap to do this in Rust though (specifically mutually-exclusive arg groups).

[–] verstra@programming.dev 11 points 2 weeks ago (1 children)

clap already supports all this: https://docs.rs/clap/latest/clap/struct.Arg.html#method.conflicts_with It's just a great library, having you could think of and applying the same parse-don't-validate mentality.

[–] TehPers@beehaw.org 9 points 1 week ago (1 children)

This doesn't represent the mutual exclusivity through the type system (which is what the article is all about).

I love clap and I use it a lot, but the only way to represent the exclusivity through the type system in Rust is through an enum.

[–] ExFed@programming.dev 5 points 1 week ago

Agreed. As nice as clap is, it's not a combinator. Parser combinators have a the really nice feature of sharing the same "shape" as the data they parse, which makes them trivial to generate from a schema ... or to just use them to represent your schema in the first place ;) .

[–] Ephera@lemmy.ml 5 points 2 weeks ago (1 children)

Clap has dependent options and mutually-exclusive argument groups built-in: https://docs.rs/clap/latest/clap/_derive/_tutorial/index.html#argument-relations

For the environment-specific requirements, you can use compiler feature flags...

[–] TehPers@beehaw.org 7 points 1 week ago (1 children)

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.

[–] Ephera@lemmy.ml 3 points 1 week 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.