Skip to main content

DefaultResolver

Struct DefaultResolver 

Source
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:

  1. If the path is absolute and the file exists, return it directly.
  2. Search the resolver’s configured search directories.
  3. 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

Source

pub fn new() -> Self

Creates a new default resolver with no search paths.

Source

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.

Source

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Resolver for DefaultResolver

Source§

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 \, and tex\stone.png names tex/stone.png when both exist.

  • .\sub.usda and ..\sub.usda are file-relative. C++ _IsFileRelative recognizes 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 name tex/stone.png. C++ leaves it as authored.

  • A letter and a colon open a Windows drive on every host, so a:b.usda is 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

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>

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

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>

Resolves an asset path to a physical location. Read more
Source§

fn resolve_for_new_asset(&self, asset_path: &str) -> Option<ResolvedPath>

Resolves an asset path for creating a new asset. Read more
Source§

fn cache_id(&self) -> Option<u64>

An id unique to this resolver among every resolver the process has made, under which a CacheScope keeps what was opened through it, or None for a resolver nothing is cached for. Read more
Source§

fn open_asset(&self, resolved_path: &ResolvedPath) -> Result<Box<dyn Asset>>

Opens a resolved asset for reading.
Source§

fn get_extension<'a>(&self, asset_path: &'a str) -> &'a str

Returns the file extension of the given asset path (without the leading dot), the innermost packaged path’s for a package-relative one.
Source§

fn get_asset_info( &self, _asset_path: &str, _resolved_path: &ResolvedPath, ) -> AssetInfo

Returns metadata about a resolved asset.
Source§

fn get_modification_timestamp( &self, _asset_path: &str, resolved_path: &ResolvedPath, ) -> Option<SystemTime>

Returns the modification timestamp of a resolved asset.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.