3 ms·
I'm not sure why the author kept &*s, I have suggested &s[..] instead (i.e. "take a slice of the whole string"). And .into() seems to be used as a &str -> Stri
by eddyb 11y ago
I'm not sure why the author kept &*s, I have suggested &s[..] instead (i.e. "take a slice of the whole string").
And .into() seems to be used as a &str -> String (allocating) conversion for brevity only.
The more idiomatic form would therefore be:
let fname = &env::args().nth(1).unwrap_or(String::from("/usr/share/dict/words"))[..];
Although I would move the &...[..] slicing to the places where fname is used, which should work fine with &String instead of &str (or automatically coerce to get the latter).