const FOO: u8 = 0;
fn bar(a: @FOO) {
println!("{}",a);
}
fn main() {
bar(3);
bar();
}
The a
parameter's type in the bar
function is same to the FOO
(u8
)
and the result is
0
I can ignore a parameter when I want to use its default value
1) The @ is already used in the language (https://doc.rust-lang.org/book/patterns.html#bindings), so you'd have to add some complexity to the parser on that side.
2) Your code would have thousands of const XX : u8 = y
, where you can't really tell the difference between the ones that used by some code, the ones that are used by default parameters and the ones used by both.
2b) Your code would have thousands of constXX : u8 = y
, making it ugly and unreadable. You would have to look for the type of FOO
to know which type to use.
3) The doc generated by cargo would be a pain to read and/or to generate. What do you intend to use in the docs generated by cargo ?
4) Of all the solutions I have seen, this one is the most confusing one. In which languages @XX
is used for default parameters exactly ?
Also please change your title, this is just click-baity and doesn't really tell us what this issue is about. Something like "Proposition to add @FOO
for default parameters"
@Cobrand I think
fn bar(a: u8 = 0){
print!("{}",a);
}
is ok, but it looks like visual basic.
Just FYI, there is a lot of discussion about this in https://github.com/rust-lang/rfcs/issues/323.
Yes, let's use that issue. Closing as duplicate!
Most helpful comment
1) The @ is already used in the language (https://doc.rust-lang.org/book/patterns.html#bindings), so you'd have to add some complexity to the parser on that side.
2) Your code would have thousands of
const XX : u8 = y
, where you can't really tell the difference between the ones that used by some code, the ones that are used by default parameters and the ones used by both.2b) Your code would have thousands of
constXX : u8 = y
, making it ugly and unreadable. You would have to look for the type ofFOO
to know which type to use.3) The doc generated by cargo would be a pain to read and/or to generate. What do you intend to use in the docs generated by cargo ?
4) Of all the solutions I have seen, this one is the most confusing one. In which languages
@XX
is used for default parameters exactly ?Also please change your title, this is just click-baity and doesn't really tell us what this issue is about. Something like "Proposition to add
@FOO
for default parameters"