Generalized Into<AssetSourceId> and Into<AssetPath> Implementations over Lifetime
#10823
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.
Objective
AssetPathFromimpls cause hard-to-diagnose compile errors #10478Solution
Generalised
From/Intoimplementations over&strandOption<&str>forAssetSourceIdandAssetPathacross all lifetimes, not just static. To maintain access to the'static-only specialisation, these types (andCowArc) now include anas_staticmethod which will apply the specialisation.This post-fix specialisation is available here because the actual specialisation performed is only a marker for if/when modification or ownership is required, making the transform a very cheap operation. For cleanliness, I've also added
from_static, which wraps this behaviour in a clean shorthand designed to replacefromcalls.Changelog
From<&'static str> for AssetSourceId<'static>From<Option<&'static str>> for AssetSourceId<'static>From<&'static str> for AssetPath<'static>From<&'static Path> for AssetPath<'static>as_staticspecialisation to:CowArcAssetSourceIdAssetPathfrom_staticspecialised constructor to:AssetSourceIdAssetPathMigration Guide
In areas where these implementations where being used, you can now add
from_staticin order to get the original specialised implementation which avoids creating anArcinternally.To be clear, this is only required if you wish to maintain the performance benefit that came with the specialisation. Existing code is not broken by this change.