Dhghomon / rust-fsharp

Rust - F# - Rust reference
MIT License
239 stars 14 forks source link

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

Open ChayimFriedman2 opened 3 years ago

ChayimFriedman2 commented 3 years ago
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.