You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
clap-derive has a parameter called default_value_t, used like arg(default_value_t = expr), or arg(default_value_t). (discussion)
serde has slightly different take, the syntax is serde(default) or serde(default = "path-to-function"). (docu: https://serde.rs/attr-default.html)
We currently have default_value = "..." which is basically the same clap.
I haven't found arg(default_value_t = ...) to be that useful. serde(default) is very useful -- I actually didn't know that arg(default_value_t) worked like that in clap.
The naming default_value_t kind of irks me -- it clashes with traditional systems programming conventions.
Traditionally, in C and C++, _t indicates that something is a type.
For example, size_t is a type used to represent a size.
In clap however, default_value_t = ... is assigned a value, and is not a type.
I find this confusing, and so I'd rather break with clap's naming and follow serde, but follow clap's semantics. So we would have arg(default) means that it is initialized with Default::default(), and arg(default = expr) mean that it is initialized with the expression.
(We would not, like serde, require that you create a named function somewhere else, when there is no good reason to make you do that afaict. We are already wrapping whatever expr you supply in a hidden function in the implementation of many things like value_parser and validation_predicate.)
The text was updated successfully, but these errors were encountered:
clap-derive
has a parameter calleddefault_value_t
, used likearg(default_value_t = expr)
, orarg(default_value_t)
. (discussion)serde
has slightly different take, the syntax isserde(default)
orserde(default = "path-to-function")
. (docu: https://serde.rs/attr-default.html)We currently have
default_value = "..."
which is basically the sameclap
.I haven't found
arg(default_value_t = ...)
to be that useful.serde(default)
is very useful -- I actually didn't know thatarg(default_value_t)
worked like that in clap.The naming
default_value_t
kind of irks me -- it clashes with traditional systems programming conventions.Traditionally, in C and C++,
_t
indicates that something is a type.For example,
size_t
is a type used to represent a size.Many more examples from C standard library and POSIX: https://stackoverflow.com/a/231807/3598119
In JSON for modern C++, the
_t
things in the API are types.In
clap
however,default_value_t = ...
is assigned a value, and is not a type.I find this confusing, and so I'd rather break with
clap
's naming and followserde
, but follow clap's semantics. So we would havearg(default)
means that it is initialized withDefault::default()
, andarg(default = expr)
mean that it is initialized with the expression.(We would not, like serde, require that you create a named function somewhere else, when there is no good reason to make you do that afaict. We are already wrapping whatever expr you supply in a hidden function in the implementation of many things like
value_parser
andvalidation_predicate
.)The text was updated successfully, but these errors were encountered: