rust-fsharp icon indicating copy to clipboard operation
rust-fsharp copied to clipboard

Taking a `&str` when you need `String` is considered unidiomatic

Open ChayimFriedman2 opened this issue 3 years ago • 0 comments

fn name(mut self, name: &str) -> Self {
    self.name = name.to_string();
    self
}

It's preferred to take String:

fn name(mut self, name: String) -> Self {
    self.name = name;
    self
}

This way, if the caller already has a String it doesn't perform an unnecessary allocation.

ChayimFriedman2 avatar Jun 03 '21 11:06 ChayimFriedman2