Closed oolonek closed 7 months ago
It is primarily for ease of use. Let's start by breaking down what the different string objects mean:
String
is the actual string object. It represents the actual memory that contains the string, which is a Struct with some fields attached to it.&'a String
would be a pointer to an actual string object, so a pointer to a struct.str
would be not a Struct, but a basic type, more akin to an u64 for instance. At run time, you cannot create an str.&'a str
instead would be a pointer to a string basic type. You can always get the underlying str from a String Struct, so when you implement the TryFrom method for &'a str
you can also implement it trivially for any of the other variants above.So if I get this right, the second block is somehow redundant ?
We could just keep the first one since we can get the the underlying str from a String Struct for &'a str
? Or is there a reason to explicity implement it ?
It is primarily a clean code thing. This way, a library user can use this ready made method without having to duplicate that logic several times.
... we had with Marco.
here
Could you explain us the purpose of this "double" implementation of TryFrom (one with the lifetime and ref the other with the object itself) ?