pub struct AssetPath<'a> { /* private fields */ }Expand description
Represents a path to an asset in a “virtual filesystem”.
Asset paths consist of three main parts:
AssetPath::source: The name of theAssetSourceto load the asset from. This is optional. If one is not set the default source will be used (which is theassetsfolder by default).AssetPath::path: The “virtual filesystem path” pointing to an asset source file.AssetPath::label: An optional “named sub asset”. When assets are loaded, they are allowed to load “sub assets” of any type, which are identified by a named “label”.
Asset paths are generally constructed (and visualized) as strings:
// This loads the `my_scene.scn` base asset from the default asset source.
let scene: Handle<Scene> = asset_server.load("my_scene.scn");
// This loads the `PlayerMesh` labeled asset from the `my_scene.scn` base asset in the default asset source.
let mesh: Handle<Mesh> = asset_server.load("my_scene.scn#PlayerMesh");
// This loads the `my_scene.scn` base asset from a custom 'remote' asset source.
let scene: Handle<Scene> = asset_server.load("remote://my_scene.scn");AssetPath implements From for &'static str, &'static Path, and &'a String,
which allows us to optimize the static cases.
This means that the common case of asset_server.load("my_scene.scn") when it creates and
clones internal owned AssetPaths.
This also means that you should use AssetPath::parse in cases where &str is the explicit type.
Implementations§
Source§impl<'a> AssetPath<'a>
impl<'a> AssetPath<'a>
Sourcepub fn parse(asset_path: &'a str) -> AssetPath<'a>
pub fn parse(asset_path: &'a str) -> AssetPath<'a>
Creates a new AssetPath from a string in the asset path format:
- An asset at the root:
"scene.gltf" - An asset nested in some folders:
"some/path/scene.gltf" - An asset with a “label”:
"some/path/scene.gltf#Mesh0" - An asset with a custom “source”:
"custom://some/path/scene.gltf#Mesh0"
Prefer From<'static str> for static strings, as this will prevent allocations
and reference counting for AssetPath::into_owned.
§Panics
Panics if the asset path is in an invalid format. Use AssetPath::try_parse for a fallible variant
Sourcepub fn try_parse(
asset_path: &'a str,
) -> Result<AssetPath<'a>, ParseAssetPathError>
pub fn try_parse( asset_path: &'a str, ) -> Result<AssetPath<'a>, ParseAssetPathError>
Creates a new AssetPath from a string in the asset path format:
- An asset at the root:
"scene.gltf" - An asset nested in some folders:
"some/path/scene.gltf" - An asset with a “label”:
"some/path/scene.gltf#Mesh0" - An asset with a custom “source”:
"custom://some/path/scene.gltf#Mesh0"
Prefer From<'static str> for static strings, as this will prevent allocations
and reference counting for AssetPath::into_owned.
This will return a ParseAssetPathError if asset_path is in an invalid format.
Sourcepub fn from_path_buf(path_buf: PathBuf) -> AssetPath<'a>
pub fn from_path_buf(path_buf: PathBuf) -> AssetPath<'a>
Sourcepub fn source(&self) -> &AssetSourceId<'_>
pub fn source(&self) -> &AssetSourceId<'_>
Gets the “asset source”, if one was defined. If none was defined, the default source will be used.
Sourcepub fn without_label(&self) -> AssetPath<'_>
pub fn without_label(&self) -> AssetPath<'_>
Gets the path to the asset in the “virtual filesystem” without a label (if a label is currently set).
Sourcepub fn remove_label(&mut self)
pub fn remove_label(&mut self)
Removes a “sub-asset label” from this AssetPath, if one was set.
Sourcepub fn take_label(&mut self) -> Option<CowArc<'a, str>>
pub fn take_label(&mut self) -> Option<CowArc<'a, str>>
Takes the “sub-asset label” from this AssetPath, if one was set.
Sourcepub fn with_label(self, label: impl Into<CowArc<'a, str>>) -> AssetPath<'a>
pub fn with_label(self, label: impl Into<CowArc<'a, str>>) -> AssetPath<'a>
Returns this asset path with the given label. This will replace the previous label if it exists.
Sourcepub fn with_source(self, source: impl Into<AssetSourceId<'a>>) -> AssetPath<'a>
pub fn with_source(self, source: impl Into<AssetSourceId<'a>>) -> AssetPath<'a>
Returns this asset path with the given asset source. This will replace the previous asset source if it exists.
Sourcepub fn parent(&self) -> Option<AssetPath<'a>>
pub fn parent(&self) -> Option<AssetPath<'a>>
Returns an AssetPath for the parent folder of this path, if there is a parent folder in the path.
Sourcepub fn into_owned(self) -> AssetPath<'static>
pub fn into_owned(self) -> AssetPath<'static>
Sourcepub fn clone_owned(&self) -> AssetPath<'static>
pub fn clone_owned(&self) -> AssetPath<'static>
Sourcepub fn resolve(&self, path: &AssetPath<'_>) -> AssetPath<'static>
pub fn resolve(&self, path: &AssetPath<'_>) -> AssetPath<'static>
Resolves an AssetPath relative to self.
Semantics:
- If
pathis label-only (default source, empty path, label set), replaceself’s label. - If
pathbegins with/, treat it as rooted at the asset-source root (not the filesystem). - If
pathhas an explicit source (name://...), it replaces the base source. - Relative segments are concatenated and normalized (
./..removal), preserving extra..if the base underflows.
let base = AssetPath::parse("a/b");
assert_eq!(base.resolve(&AssetPath::parse("c")), AssetPath::parse("a/b/c"));
assert_eq!(base.resolve(&AssetPath::parse("./c")), AssetPath::parse("a/b/c"));
assert_eq!(base.resolve(&AssetPath::parse("../c")), AssetPath::parse("a/c"));
assert_eq!(base.resolve(&AssetPath::parse("c.png")), AssetPath::parse("a/b/c.png"));
assert_eq!(base.resolve(&AssetPath::parse("/c")), AssetPath::parse("c"));
assert_eq!(AssetPath::parse("a/b.png").resolve(&AssetPath::parse("#c")), AssetPath::parse("a/b.png#c"));
assert_eq!(AssetPath::parse("a/b.png#c").resolve(&AssetPath::parse("#d")), AssetPath::parse("a/b.png#d"));See also AssetPath::resolve_str.
Sourcepub fn resolve_embed(&self, path: &AssetPath<'_>) -> AssetPath<'static>
pub fn resolve_embed(&self, path: &AssetPath<'_>) -> AssetPath<'static>
Resolves an AssetPath relative to self using embedded (RFC 1808) semantics.
Semantics:
- Remove the “file portion” of the base before concatenation (unless the base ends with
/). - Otherwise identical to
AssetPath::resolve.
let base = AssetPath::parse("a/b");
assert_eq!(base.resolve_embed(&AssetPath::parse("c")), AssetPath::parse("a/c"));
assert_eq!(base.resolve_embed(&AssetPath::parse("./c")), AssetPath::parse("a/c"));
assert_eq!(base.resolve_embed(&AssetPath::parse("../c")), AssetPath::parse("c"));
assert_eq!(base.resolve_embed(&AssetPath::parse("c.png")), AssetPath::parse("a/c.png"));
assert_eq!(base.resolve_embed(&AssetPath::parse("/c")), AssetPath::parse("c"));
assert_eq!(AssetPath::parse("a/b.png").resolve_embed(&AssetPath::parse("#c")), AssetPath::parse("a/b.png#c"));
assert_eq!(AssetPath::parse("a/b.png#c").resolve_embed(&AssetPath::parse("#d")), AssetPath::parse("a/b.png#d"));See also AssetPath::resolve_embed_str.
Sourcepub fn resolve_str(
&self,
path: &str,
) -> Result<AssetPath<'static>, ParseAssetPathError>
pub fn resolve_str( &self, path: &str, ) -> Result<AssetPath<'static>, ParseAssetPathError>
Parses path as an AssetPath, then resolves it relative to self.
Returns an error if parsing fails.
For more details, see AssetPath::resolve.
Sourcepub fn resolve_embed_str(
&self,
path: &str,
) -> Result<AssetPath<'static>, ParseAssetPathError>
pub fn resolve_embed_str( &self, path: &str, ) -> Result<AssetPath<'static>, ParseAssetPathError>
Parses path as an AssetPath, then resolves it relative to self using embedded
(RFC 1808) semantics.
Returns an error if parsing fails.
For more details, see AssetPath::resolve_embed.
Sourcepub fn get_full_extension(&self) -> Option<&str>
pub fn get_full_extension(&self) -> Option<&str>
Returns the full extension (including multiple ‘.’ values).
Ex: Returns "config.ron" for "my_asset.config.ron"
Also strips out anything following a ? to handle query parameters in URIs
Sourcepub fn get_extension(&self) -> Option<&str>
pub fn get_extension(&self) -> Option<&str>
Returns the extension, excluding multiple . values.
Ex: Returns "ron" for "my_asset.config.ron"
Also strips out anything follow a ? to handle query parameters in URIs.
Sourcepub fn is_unapproved(&self) -> bool
pub fn is_unapproved(&self) -> bool
Returns true if this AssetPath points to a file that is
outside of its AssetSource folder.
§Example
// Inside the default AssetSource.
let path = AssetPath::parse("thingy.png");
assert!( ! path.is_unapproved());
let path = AssetPath::parse("gui/thingy.png");
assert!( ! path.is_unapproved());
// Inside a different AssetSource.
let path = AssetPath::parse("embedded://thingy.png");
assert!( ! path.is_unapproved());
// Exits the `AssetSource`s directory.
let path = AssetPath::parse("../thingy.png");
assert!(path.is_unapproved());
let path = AssetPath::parse("folder/../../thingy.png");
assert!(path.is_unapproved());
// This references the linux root directory.
let path = AssetPath::parse("/home/thingy.png");
assert!(path.is_unapproved());Trait Implementations§
Source§impl<'de> Deserialize<'de> for AssetPath<'static>
impl<'de> Deserialize<'de> for AssetPath<'static>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'a> FromReflect for AssetPath<'a>where
AssetPath<'a>: 'static,
impl<'a> FromReflect for AssetPath<'a>where
AssetPath<'a>: 'static,
Source§fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self>
fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self>
Self from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Self using,
constructing the value using from_reflect if that fails. Read moreSource§impl<'a> GetTypeRegistration for AssetPath<'a>where
AssetPath<'a>: 'static,
impl<'a> GetTypeRegistration for AssetPath<'a>where
AssetPath<'a>: 'static,
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration for this type.Source§fn register_type_dependencies(_registry: &mut TypeRegistry)
fn register_type_dependencies(_registry: &mut TypeRegistry)
Source§impl<'a> PartialReflect for AssetPath<'a>where
AssetPath<'a>: 'static,
impl<'a> PartialReflect for AssetPath<'a>where
AssetPath<'a>: 'static,
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn to_dynamic(&self) -> Box<dyn PartialReflect>
fn to_dynamic(&self) -> Box<dyn PartialReflect>
Source§fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>
fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Source§fn reflect_owned(self: Box<Self>) -> ReflectOwned
fn reflect_owned(self: Box<Self>) -> ReflectOwned
Source§fn try_into_reflect(
self: Box<Self>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<Self>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Source§fn try_as_reflect(&self) -> Option<&dyn Reflect>
fn try_as_reflect(&self) -> Option<&dyn Reflect>
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
Source§fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect>
Source§fn as_partial_reflect(&self) -> &dyn PartialReflect
fn as_partial_reflect(&self) -> &dyn PartialReflect
Source§fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect
fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect
Source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option<bool>
Source§fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
Self using reflection. Read moreSource§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Source§fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
PartialReflect, combines reflect_clone and
take in a useful fashion, automatically constructing an appropriate
ReflectCloneError if the downcast fails.Source§fn reflect_partial_cmp(
&self,
_value: &(dyn PartialReflect + 'static),
) -> Option<Ordering>
fn reflect_partial_cmp( &self, _value: &(dyn PartialReflect + 'static), ) -> Option<Ordering>
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Source§impl<'a> Reflect for AssetPath<'a>where
AssetPath<'a>: 'static,
impl<'a> Reflect for AssetPath<'a>where
AssetPath<'a>: 'static,
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any. Read moreSource§fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
Source§fn as_reflect(&self) -> &dyn Reflect
fn as_reflect(&self) -> &dyn Reflect
Source§fn as_reflect_mut(&mut self) -> &mut dyn Reflect
fn as_reflect_mut(&mut self) -> &mut dyn Reflect
Source§impl<'a> TypePath for AssetPath<'a>where
AssetPath<'a>: 'static,
impl<'a> TypePath for AssetPath<'a>where
AssetPath<'a>: 'static,
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
impl<'a> Eq for AssetPath<'a>
impl<'a> StructuralPartialEq for AssetPath<'a>
Auto Trait Implementations§
impl<'a> Freeze for AssetPath<'a>
impl<'a> RefUnwindSafe for AssetPath<'a>
impl<'a> Send for AssetPath<'a>
impl<'a> Sync for AssetPath<'a>
impl<'a> Unpin for AssetPath<'a>
impl<'a> UnsafeUnpin for AssetPath<'a>
impl<'a> UnwindSafe for AssetPath<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
Typed::type_info.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FromTemplate for T
impl<T> FromTemplate for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreSource§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<T> Template for T
impl<T> Template for T
Source§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.Source§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.