In Rust, the last expression of a function is automatically returned so a lot of returns in your code can be easily removed. Also, within an impl block you can use Self to refer to the type you're implementing stuff on.
match is also an expression so your list_command fn can be -
fnlist_command(parts:Vec<&str>,org:&mutOrganisation)->Action{matchparts.len(){1=>{org.print();Action::Done}2=>{org.print_department(String::from(parts[1]));Action::Done}_=>Action::Failure(String::from("Unexpected usage. Expect 0 or 1 parameters for list"))}
Thanks for those tips. I was aware that you can return without using the keyword 'return', but old habits kicked in when I wrote this :)
Thinking about it, the explicitness of having the 'return' keyword is something I find nice, to quickly scan a function to easily identify the places it returns.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In Rust, the last expression of a function is automatically returned so a lot of
returns in your code can be easily removed. Also, within animplblock you can useSelfto refer to the type you're implementing stuff on.For example, in
you can remove the
returnand useSelfto make itSimilarly you can do -
matchis also an expression so yourlist_commandfn can be -Thanks for those tips. I was aware that you can return without using the keyword 'return', but old habits kicked in when I wrote this :)
Thinking about it, the explicitness of having the 'return' keyword is something I find nice, to quickly scan a function to easily identify the places it returns.