-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Add AssetPath::resolve_path and resolve_embed_path methods #22416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
8c2cda9
828504a
2fa8817
61098c1
34bd56e
5373d9b
25ef7c2
d099025
f28f047
86b2ad7
65934b1
005a371
bfeeb6d
b44f587
4e107a0
8343031
6b0b8c6
5fe21a8
7e69298
4fa10f3
1abc2f6
ba14cda
ede5156
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -416,6 +416,121 @@ impl<'a> AssetPath<'a> { | |||
| self.resolve_internal(path, true) | ||||
| } | ||||
|
|
||||
| /// Resolves `path` relative to `self`, using the same rules as [`AssetPath::resolve`], | ||||
| /// but without reparsing from a string. | ||||
| /// | ||||
| /// This is equivalent to `self.resolve(&path.to_string())` for all `AssetPath` values. | ||||
| /// | ||||
| /// Notes / edge cases (kept consistent with `resolve`): | ||||
| /// - If `path` formats as `#label` (default source, empty path, label set), this replaces | ||||
| /// `self`'s label while keeping the base path. | ||||
| /// - If `path` formats as a "full" path like `/foo/bar`, this is treated as rooted at the | ||||
| /// asset source root (not the filesystem). | ||||
| /// - If `path` includes an explicit source (`name://...`), it replaces the base source. | ||||
| /// | ||||
| /// This method is additive and does not change the behavior of [`AssetPath::resolve`]. | ||||
| pub fn resolve_path(&self, path: &AssetPath<'_>) -> AssetPath<'static> { | ||||
| // Check if this is a "label-only" case: default source + empty path + label set | ||||
| let is_label_only = matches!(path.source(), AssetSourceId::Default) | ||||
| && path.path().as_os_str().is_empty() | ||||
| && path.label().is_some(); | ||||
|
|
||||
| if is_label_only { | ||||
| // Label-only: replace label on base path | ||||
| self.clone_owned() | ||||
| .with_label(path.label().unwrap().to_owned()) | ||||
| } else { | ||||
| // Determine if the input has an explicit (non-default) source | ||||
|
||||
| // Determine if the input has an explicit (non-default) source |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why (per RFC 1808) in the comment was removed?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to just extend each test below. I.e. in addition to resolve_str, just add the regular resolve. This scales much better.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change the description of
resolveinstead and mention that it parses the asset path from the string?