Replace from_com and into_com with From implementations #126
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.
Given that these from_com and into_com methods are all safe anyway, there's no good reason not to use From instead
Rewrite them as
impl From<ITYPE> for TYPE
andimpl From<ITYPE> for TYPE
.In a few cases, the second (which would have been into_com before) did not exist, but made sense, so I added them.
As per general Rust guidance, implementing From, as that also results in the blanket
Into
implementation.In the vast majority of cases, ownership was required, so I went with
impl From<ITYPE> for TYPE
instead ofimpl From<&ITYPE> for TYPE
, as in some cases, this will save a reference count increment, and in the other case, it just moves where .clone is called, and those implementations won't be called frequently outside the library.This also saved a few unnecessary clones inside the library that we appear to have had by accident.
Note in a few cases this makes it possible to construct the individual client wrappers outside the library (where we didn't have pub on from_com before). This is in my view a feature.
This will require any code outside this library to replace from_com with from and into_com with .into, but that shouldn't be a big deal.
I left
FabricClient::from_com
alone because the comment says the method is intended to be private eventually.