Skip to main content

AssetPath

Struct AssetPath 

Source
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.png
  • audio/music/theme.ogg
  • shaders/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>

Source

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");
Source

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");
Source

pub fn as_str(&self) -> &str

Returns the path as a string slice.

Source

pub fn is_empty(&self) -> bool

Returns true if the path is empty.

Source

pub fn len(&self) -> usize

Returns the length of the path in bytes.

Source

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);
Source

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);
Source

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);
Source

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"));
Source

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.

Source

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");
Source

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");
Source

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§

Source§

impl<'a> AsRef<str> for AssetPath<'a>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Clone for AssetPath<'a>

Source§

fn clone(&self) -> AssetPath<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for AssetPath<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Display for AssetPath<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a str> for AssetPath<'a>

Source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for AssetPath<'static>

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl<'a> Hash for AssetPath<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq<&str> for AssetPath<'a>

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<str> for AssetPath<'a>

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq for AssetPath<'a>

Source§

fn eq(&self, other: &AssetPath<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for AssetPath<'a>

Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> QueryState for T
where T: Send + Sync + Clone + 'static,

Source§

impl<T> Resource for T
where T: Send + Sync + 'static,