|
|
|
|
|
by weirdwitch
3028 days ago
|
|
Anything implemented for &str is automatically implemented for String, because String implements Deref<Target=str>. Most useful "String" methods are actually &str methods that you get access to through that deref trait. Dereferencing a String doesn't return a raw pointer, I'm not sure where you got that idea. |
|
Dereferencing a string does not return a raw pointer, that was exaggeration on my behalf. But a string is a container, so *string returns.... &str? But string.deref() returns str?
Don't get me wrong, I'm fully invested in the language [0], [1], [2], but it's got a lot of warts that could have been avoided by thinking bigger picture. So many APIs are restricted by thinking easy instead of big pre-1.0. Like str being hardcoded into APIs that should have been generic (FromStr vs From<&str>, .parse() vs .into()), shipping 1.0 without async/await, and the whole mess with strings.
0: https://github.com/rust-lang/rust/issues?utf8=%E2%9C%93&q=is...
1: https://github.com/rust-lang/rfcs/issues?utf8=%E2%9C%93&q=is...
2: https://crates.io/search?q=neosmart