Hi I want to ask something about common conversion traits which I find helpful but little confusing in Rust
Mainly it's about FromStr
vs From<String>
vs Display
, etc. as converting from/to String
is quite common
-
what's difference between
TryFrom<&str>
andFromStr
? which one should I impl for my custom type ? -
By impl
From<String>
, I automatically haveInto<String>
, this is good.
But by implDisplay
, I also have ato_string()
method whose name also suggests a conversion into String, which one should I use? -
I have seen many librarys impl raw methods like
into_str
,into_string
,into_u8
as conversion method, which ignores all above utility. Is this simply history reason and we should try not doing so?
There are many other scenarios which make me confusing
Generally, if all these looking-similiar traits should manually be impled identically, why does rust have them each?
Or if they have difference semantics and use cases, what's that and why does they have seemingly un-distinguishable method name ?
Thanks in advance!