Switch from TryFrom to FromStr for Manifest #107
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes
Manifest
andRawManifest
to implement theFromStr
trait rather than theTryFrom<String>
trait.While both traits can be used and do achieve a similar purpose, there is one important difference in their semantics related to what they do with the string they are taking:
TryFrom<String>
attempts to consume aString
and convert it into the target type (Manifest
orRawManifest
). The ownership of theString
is thereby moved during the conversion. This is therefore useful if you do need ownership of the input type.FromStr
trait attempts to parse a&str
(reference to a string) into the target type (Manifest
orRawManifest
). It does not take ownership of the string, only a read-only reference to it. This is therefore useful if you only need to read the input string.Since fundamentally, are are just parsing a string and we do not need it anymore after the parsing operation, the
FromStr
trait is more useful here because it does not require us to consume to the string. TheTryFrom<String>
trait would be more appropriate if we wanted to hold on to the original string after the parsing operation, and perhaps store that inside theManifest
type.But since we simply discard the string, there is no good reason to use
TryFrom
. For this reason, this PR changes the code base to useFromStr
instead.