Skip to main content

ResourceRegistry

Struct ResourceRegistry 

Source
pub struct ResourceRegistry {
    pub excluded_folders: FxHashSet<PathBuf>,
    /* private fields */
}
Expand description

Resource registry is responsible for UUID mapping of resource files. It maintains a map of UUID -> Resource Path.

Fields§

§excluded_folders: FxHashSet<PathBuf>

A list of folder that should be excluded when scanning the project folder for supported resources. By default, it contains ./target (a folder with build artifacts) and ./build (a folder with production builds) folders.

Implementations§

Source§

impl ResourceRegistry

Source

pub const DEFAULT_PATH: &'static str = "data/resources.registry"

Default path of the registry. It can be overridden on a registry instance using Self::set_path method.

Source

pub fn new(io: Arc<dyn ResourceIo>) -> Self

Creates a new resource registry with the given resource IO.

Source

pub fn status_flag(&self) -> ResourceRegistryStatusFlag

Returns a shared reference to the status flag. See ResourceRegistryStatusFlag docs for more info.

Source

pub fn normalize_path(&self, path: impl AsRef<Path>) -> PathBuf

Normalizes the path by resolving all . and .. and removing any prefixes. Absolute paths are converted to relative paths by removing the project root prefix, if possible. Also replaces \\ slashes to cross-platform / slashes.

§Panics

Panics if the given path is invalid, such as if it includes a directory that does not exist.

Source

pub fn inner(&self) -> &RegistryContainer

Returns a reference to the actual container of the resource entries.

Source

pub fn set_path(&mut self, path: impl AsRef<Path>)

Sets a new path for the registry, but does not saves it.

Source

pub fn path(&self) -> &Path

Returns a path to which the resource registry is (or may) be saved.

Source

pub fn directory(&self) -> Option<&Path>

Returns a directory to which the resource registry is (or may) be saved.

Source

pub async fn save(&self)

Asynchronously saves the registry.

Source

pub fn exists_sync(&self) -> bool

Returns true if the resource registry file exists, false - otherwise.

Source

pub fn save_sync(&self)

Same as Self::save, but synchronous.

Source

pub fn modify(&mut self) -> ResourceRegistryRefMut<'_>

Begins registry modification. See ResourceRegistryRefMut docs for more info.

Source

pub fn uuid_to_path(&self, uuid: Uuid) -> Option<&Path>

Tries to get a path associated with the given resource UUID.

Source

pub fn uuid_to_path_buf(&self, uuid: Uuid) -> Option<PathBuf>

Same as Self::uuid_to_path, but returns PathBuf instead of &Path.

Source

pub fn path_to_uuid(&self, path: &Path) -> Option<Uuid>

Tries to find a UUID that corresponds for the given path.

Source

pub fn is_registered(&self, path: &Path) -> bool

Checks if the path is registered in the resource registry.

Source

pub async fn scan( resource_io: Arc<dyn ResourceIo>, loaders: Arc<Mutex<ResourceLoadersContainer>>, root: impl AsRef<Path>, excluded_folders: FxHashSet<PathBuf>, ) -> RegistryContainer

Searches for supported resources starting from the given path and builds a mapping UUID -> Path. If a supported resource does not have a metadata file besides it, this method will automatically create the metadata file with a new UUID and add the resource to the registry.

This method does not load any resource, instead it checks extension of every file in the given directory, and if there’s a loader for it, “remember” the resource.

Trait Implementations§

Source§

impl Clone for ResourceRegistry

Source§

fn clone(&self) -> ResourceRegistry

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

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> AsyncTaskResult for T
where T: Any + Send + 'static,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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<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> ObjectOrVariant<T> for U

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V