Generalized Into<AssetSourceId> and Into<AssetPath> Implementations over Lifetime#10823
Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom Aug 19, 2024
Conversation
doonv
approved these changes
Jan 9, 2024
SludgePhD
approved these changes
Jul 22, 2024
Member
|
Merging once merge conflicts are resolved :) |
Allows creating `AssetSourceId` and `AssetPath` from non-static lifetimes using the `From/Into` implementations over `&str` and `Option<&str>`. Added `as_static` and `from_static` methods to allow a work-around specialization.
773e844 to
5068b6a
Compare
Merged
4 tasks
github-merge-queue bot
pushed a commit
that referenced
this pull request
Aug 15, 2025
…in AssetServer::load() (#20562) # Objective - Fixes #19844 ## Solution - Revert #10823 - Also reverts #19094, as the ignored test added there does not compile with the new lifetime rules. ## TODO This PR was made > 10k issues ago, and git can do funky things. Opening as a draft to investigate the diff before proceeding. - [x] merge main into the old branch - [x] revert the PR - [x] make sure the diff looks okay - [x] add comments explaining why we did this weird thing --------- Co-authored-by: Zac Harrold <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.