Rfcs: Proposition to add some keyword for default parameters

Created on 28 Oct 2016  路  4Comments  路  Source: rust-lang/rfcs

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

T-lang

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 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"

All 4 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sfackler picture sfackler  路  167Comments

pnkfelix picture pnkfelix  路  69Comments

steveklabnik picture steveklabnik  路  69Comments

pnkfelix picture pnkfelix  路  160Comments

Ekleog picture Ekleog  路  204Comments