pub struct AssetPath<'a> { /* private fields */ }Expand description
A path identifier for assets.
AssetPath represents the path used to load an asset, supporting both
owned and borrowed string data. It provides utility methods for working
with asset paths.
§Path Format
Asset paths use forward slashes as separators, regardless of platform:
textures/player.pngaudio/music/theme.oggshaders/basic.vert
§FFI Considerations
For FFI, convert to a C string using as_str() and standard FFI string
handling. The path does not include a null terminator by default.
§Example
use goud_engine::assets::AssetPath;
let path = AssetPath::new("textures/player.png");
assert_eq!(path.as_str(), "textures/player.png");
assert_eq!(path.file_name(), Some("player.png"));
assert_eq!(path.extension(), Some("png"));
assert_eq!(path.directory(), Some("textures"));
// From owned string
let owned = AssetPath::from_string("audio/sfx/jump.wav".to_string());
assert_eq!(owned.extension(), Some("wav"));Implementations§
Source§impl<'a> AssetPath<'a>
impl<'a> AssetPath<'a>
Sourcepub fn new(path: &'a str) -> Self
pub fn new(path: &'a str) -> Self
Creates a new asset path from a string slice.
§Example
use goud_engine::assets::AssetPath;
let path = AssetPath::new("textures/player.png");
assert_eq!(path.as_str(), "textures/player.png");Sourcepub fn from_string(path: String) -> AssetPath<'static>
pub fn from_string(path: String) -> AssetPath<'static>
Creates a new asset path from an owned string.
§Example
use goud_engine::assets::AssetPath;
let path = AssetPath::from_string("textures/player.png".to_string());
assert_eq!(path.as_str(), "textures/player.png");Sourcepub fn file_name(&self) -> Option<&str>
pub fn file_name(&self) -> Option<&str>
Returns the file name component of the path.
§Example
use goud_engine::assets::AssetPath;
assert_eq!(AssetPath::new("textures/player.png").file_name(), Some("player.png"));
assert_eq!(AssetPath::new("player.png").file_name(), Some("player.png"));
assert_eq!(AssetPath::new("textures/").file_name(), None);Sourcepub fn extension(&self) -> Option<&str>
pub fn extension(&self) -> Option<&str>
Returns the file extension, if any.
§Example
use goud_engine::assets::AssetPath;
assert_eq!(AssetPath::new("player.png").extension(), Some("png"));
assert_eq!(AssetPath::new("textures/player.png").extension(), Some("png"));
assert_eq!(AssetPath::new("Makefile").extension(), None);
assert_eq!(AssetPath::new(".gitignore").extension(), None);Sourcepub fn directory(&self) -> Option<&str>
pub fn directory(&self) -> Option<&str>
Returns the directory component of the path.
§Example
use goud_engine::assets::AssetPath;
assert_eq!(AssetPath::new("textures/player.png").directory(), Some("textures"));
assert_eq!(AssetPath::new("a/b/c/file.txt").directory(), Some("a/b/c"));
assert_eq!(AssetPath::new("file.txt").directory(), None);Sourcepub fn stem(&self) -> Option<&str>
pub fn stem(&self) -> Option<&str>
Returns the file stem (file name without extension).
§Example
use goud_engine::assets::AssetPath;
assert_eq!(AssetPath::new("player.png").stem(), Some("player"));
assert_eq!(AssetPath::new("textures/player.png").stem(), Some("player"));
assert_eq!(AssetPath::new("archive.tar.gz").stem(), Some("archive.tar"));
assert_eq!(AssetPath::new(".gitignore").stem(), Some(".gitignore"));Sourcepub fn into_owned(self) -> AssetPath<'static>
pub fn into_owned(self) -> AssetPath<'static>
Converts this path to an owned AssetPath<'static>.
If the path is already owned, this is a no-op. If borrowed, the string is cloned.
Sourcepub fn from_path(path: &Path) -> AssetPath<'static>
pub fn from_path(path: &Path) -> AssetPath<'static>
Creates an AssetPath from a std::path::Path.
Converts backslashes to forward slashes for platform consistency.
§Example
use goud_engine::assets::AssetPath;
use std::path::Path;
let path = AssetPath::from_path(Path::new("textures/player.png"));
assert_eq!(path.as_str(), "textures/player.png");Sourcepub fn join(&self, other: &str) -> AssetPath<'static>
pub fn join(&self, other: &str) -> AssetPath<'static>
Joins this path with another path component.
§Example
use goud_engine::assets::AssetPath;
let base = AssetPath::new("textures");
let full = base.join("player.png");
assert_eq!(full.as_str(), "textures/player.png");
// Handles trailing slashes
let base = AssetPath::new("textures/");
let full = base.join("player.png");
assert_eq!(full.as_str(), "textures/player.png");Sourcepub fn with_extension(&self, ext: &str) -> AssetPath<'static>
pub fn with_extension(&self, ext: &str) -> AssetPath<'static>
Returns the path with a different extension.
§Example
use goud_engine::assets::AssetPath;
let path = AssetPath::new("textures/player.png");
let new_path = path.with_extension("jpg");
assert_eq!(new_path.as_str(), "textures/player.jpg");
// Add extension to file without one
let path = AssetPath::new("Makefile");
let new_path = path.with_extension("bak");
assert_eq!(new_path.as_str(), "Makefile.bak");Trait Implementations§
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more