Is it possible to call a function in Rust by naming its arguments?

Therefore my question is: Is naming arguments in function call is possible in Rust

Rust does not support named parameters as part of the language.

is it considered to be a good practice according to Rust best practices? (I’m a beginner)

Generally not (the rather strong typing usually helps mitigate this issue)

In cases where it really is useful two patterns crop up repeatedly:

  • an options struct, the function would have a limited number of simple parameters and a named structure to pass more structured data, providing “naming”
  • the builder pattern, which is an evolved and more literate version of the former (and more conducive to optional parameters)

See the article linked to https://old.reddit.com/r/rust/comments/fg6vrn/for_your_consideration_an_alternative_to_the/ for more information (I’m linking to the thread because there is useful discussion of the options, as well as links to helpful crates).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)