3 ms·
What would be the ... in this case?
by ridiculous_fish 6y ago
What would be the ... in this case?
- Arnavion 6y agoIt's a bad suggestion for this case [1]. The ... would have to be `impl Iterator<Item = String>`, because the function would not have anything to return a borrow from. That is exactly the problem the original article was trying to avoid in the first place. [1]: And arguably a bad suggestion in general. If a fn needs a String, it should take a String. If it needs a &str, it should take a &str, and if the caller has a String they can call the fn with a borrow. fns that are generic on AsRef<str> are usually only found where the ergonomics make it worth it. Eg the standard library's filesystem functions often take AsRef<Path> parameters because string literals are AsRef<Path>, which means you can write fs::read_to_string("/etc/passwd") instead of a more cumbersome fs::read_to_string(Path::new(OsStr::new("/etc/passwd")))
- timvisee 6y agoYou're right! Didn't think about it much before posting.