Implement cast from lifetime-free to unbound types #24
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.
The
TryCast{Mut,Ref,Owned}LifetimeFree
traits are implemented forLifetimeFree
target types, but not implemented forLifetimeFree
source types.This PR adds
TryCast{Mut,Ref,Owned}LifetimeFreeBack
traits with source types bounded byLifetimeFree
trait.This makes it possible to upcast types and make specialized builders/decoders/constructors like this:
This PR is based on (includes) another PR #23 and might require rebase before merging if needed. This PR includes additional tests for both PRs. You can use last commit (7b75e1e if not changed) for better diffs related to this PR changes only.
Common implementations for
*LifetimeFree::try_cast
and*LifetimeFreeBack::try_cast
methods are extracted into separate private functions to reduce boilerplate code.New autoderef ordering:
TryCastMutLifetimeFree
,TryCastMutLifetimeFreeBack
(new),TryCastRefLifetimeFree
,TryCastRefLifetimeFreeBack
(new),TryCastOwnedLifetimeFree
,TryCastOwnedLifetimeFreeBack
(new),TryCastSliceMut
,TryCastSliceRef
,TryCastMut
,TryCastRef
,TryCastOwned