pub struct DefaultResolver { /* private fields */ }Expand description
Default filesystem-based asset resolver.
Resolves asset paths by searching the filesystem using a configurable list of search directories. Resolution proceeds in order:
- If the path is absolute and the file exists, return it directly.
- Search the resolver’s configured search directories.
- Search relative to the current working directory.
§Correspondence
This corresponds to ArDefaultResolver in the C++ USD API:
https://openusd.org/dev/api/class_ar_default_resolver.html
A file asset is read into memory unless the resolver was told to map
files (map_files), in which case it is served from a
read-only memory mapping and a layer holds no copy of its file.
Implementations§
Source§impl DefaultResolver
impl DefaultResolver
Sourcepub unsafe fn map_files(self) -> Self
pub unsafe fn map_files(self) -> Self
Serves every file asset from a read-only memory mapping of it. A layer then holds no copy of its file, and only the pages a read touches are loaded. An empty file, or one the platform cannot map, is read into memory.
§Safety
A mapped file must not be modified, by this process or any other,
while anything read from it is alive: a layer, a package index, or an
AssetBuffer view. The caller guarantees that for every file this
resolver serves. The library upholds its half by never writing into a
file it holds a view of: Layer::save
writes beside the file and renames over it, which unlinks the mapped
file and leaves its bytes as they are. On Windows the mapped file is
opened with write sharing denied, which keeps other handles from
opening it for writing meanwhile and refuses to open a file a handle
already has open for writing, and with delete sharing allowed, which
lets a rename over it go through. Neither establishes the guarantee.
If it is broken, a read faults the process when the file has shrunk
and is undefined behaviour otherwise.
Sourcepub fn with_search_paths(
paths: impl IntoIterator<Item = impl Into<PathBuf>>,
) -> Self
pub fn with_search_paths( paths: impl IntoIterator<Item = impl Into<PathBuf>>, ) -> Self
Creates a new default resolver with the given search paths.
Each path is canonicalized to a stable spelling — relative paths are
anchored to the current working directory and lexical noise (.
components, redundant and trailing separators) is collapsed — so that
directories named equivalently resolve, and render via
identity, identically.
Trait Implementations§
Source§impl Default for DefaultResolver
impl Default for DefaultResolver
Source§impl Resolver for DefaultResolver
impl Resolver for DefaultResolver
Source§fn create_identifier(
&self,
asset_path: &str,
anchor: Option<&ResolvedPath>,
) -> String
fn create_identifier( &self, asset_path: &str, anchor: Option<&ResolvedPath>, ) -> String
Anchors a relative asset_path against anchor’s directory, with the
look-here-first rule of C++ ArDefaultResolver::_CreateIdentifier: a
search path (relative, not spelled from . or ..) whose anchored
candidate does not exist keeps its bare normalized spelling, so
resolving the identifier goes through the search directories and a
@usd/schema.usda@ sublayer is found beside any layer that names it.
A relative path is read with \ as a separator on every host, the
rule C++ ArchNormPath applies on Windows, so a layer authored there
(@tex\stone.png@) names the same asset everywhere. That departs
from C++ in four ways:
-
C++ on a POSIX host keeps
\as a file-name byte. Here a relative asset path cannot name a file whose name contains\, andtex\stone.pngnamestex/stone.pngwhen both exist. -
.\sub.usdaand..\sub.usdaare file-relative. C++_IsFileRelativerecognizes the/spellings only, so on Windows it searches for.\sub.usda. -
The packaged path of
pkg.usdz[tex\stone.png]is normalized to the entry nametex/stone.png. C++ leaves it as authored. -
A letter and a colon open a Windows drive on every host, so
a:b.usdais absolute. C++ on a POSIX host reads it as a relative path to a file of that name. A longer prefix (ab:c.usda) is an ordinary file name.
A path absolute for another platform (C:\tex\a.png or a:b.usda on
Unix) names no location on this host and is returned unchanged.
Source§fn is_context_dependent_path(&self, asset_path: &str) -> bool
fn is_context_dependent_path(&self, asset_path: &str) -> bool
Whether asset_path is a search path, the one form whose identifier
follows the filesystem: it stays bare until an asset appears beside
the layer that authors it (C++
ArDefaultResolver::_IsContextDependentPath).
Source§fn in_memory_identifier<'a>(&self, asset_path: &'a str) -> Cow<'a, str>
fn in_memory_identifier<'a>(&self, asset_path: &'a str) -> Cow<'a, str>
A relative asset_path in its normalized spelling (\ read as a
separator, . segments and repeated separators dropped), and the
packaged part of a package-relative one as the entry name it reaches.
So sub\layer.usda, ./sub/layer.usda and sub/layer.usda all name
the in-memory layer sub/layer.usda. An absolute path is returned
unchanged.
Source§fn identity(&self) -> String
fn identity(&self) -> String
Renders the canonicalized search paths as the resolver’s identity token,
so two DefaultResolvers with different search roots key distinct stacks.
Each path is rendered via Debug, which escapes
losslessly — including newlines and non-UTF-8 bytes that
to_string_lossy would flatten — and
wraps each segment in quotes. The concatenation is therefore injective:
distinct path lists never collapse to the same token.
Source§fn resolve(&self, asset_path: &str) -> Option<ResolvedPath>
fn resolve(&self, asset_path: &str) -> Option<ResolvedPath>
Source§fn resolve_for_new_asset(&self, asset_path: &str) -> Option<ResolvedPath>
fn resolve_for_new_asset(&self, asset_path: &str) -> Option<ResolvedPath>
Source§fn cache_id(&self) -> Option<u64>
fn cache_id(&self) -> Option<u64>
CacheScope keeps what was opened through it,
or None for a resolver nothing is cached for. Read more