Is it possible to define optional arguments within functions in Rust? -
Whether correction allows for alternative function arguments, which I can set to some default value, such as pattern matching or Some other mechanisms?
Not technically, but you can close the option
enum Always available to get the same effect:
fn opt_arg (i: option ) {match i {some (x) = & gt; {Println! ("Understand {}", x); }, None = & gt; {Println! ("Nothing found"); }}} Fn Main () {opt_arg (none); // none found the opt_group (some (2i)); // got 2}
Comments
Post a Comment