pub struct ResourceRegistry {
pub excluded_folders: HashSet<PathBuf, BuildHasherDefault<FxHasher>>,
/* 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: HashSet<PathBuf, BuildHasherDefault<FxHasher>>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
impl ResourceRegistry
Sourcepub const DEFAULT_PATH: &'static str = "data/resources.registry"
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.
Sourcepub fn new(io: Arc<dyn ResourceIo>) -> ResourceRegistry
pub fn new(io: Arc<dyn ResourceIo>) -> ResourceRegistry
Creates a new resource registry with the given resource IO.
Sourcepub fn status_flag(&self) -> ResourceRegistryStatusFlag
pub fn status_flag(&self) -> ResourceRegistryStatusFlag
Returns a shared reference to the status flag. See ResourceRegistryStatusFlag docs for
more info.
Sourcepub fn normalize_path(&self, path: impl AsRef<Path>) -> PathBuf
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.
Sourcepub fn inner(&self) -> &BTreeMap<Uuid, PathBuf>
pub fn inner(&self) -> &BTreeMap<Uuid, PathBuf>
Returns a reference to the actual container of the resource entries.
Sourcepub fn set_path(&mut self, path: impl AsRef<Path>)
pub fn set_path(&mut self, path: impl AsRef<Path>)
Sets a new path for the registry, but does not saves it.
Sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
Returns a path to which the resource registry is (or may) be saved.
Sourcepub fn directory(&self) -> Option<&Path>
pub fn directory(&self) -> Option<&Path>
Returns a directory to which the resource registry is (or may) be saved.
Sourcepub fn exists_sync(&self) -> bool
pub fn exists_sync(&self) -> bool
Returns true if the resource registry file exists, false - otherwise.
Sourcepub fn save_sync(&self)
pub fn save_sync(&self)
Same as Self::save, but synchronous.
Sourcepub fn modify(&mut self) -> ResourceRegistryRefMut<'_>
pub fn modify(&mut self) -> ResourceRegistryRefMut<'_>
Begins registry modification. See ResourceRegistryRefMut docs for more info.
Sourcepub fn uuid_to_path(&self, uuid: Uuid) -> Option<&Path>
pub fn uuid_to_path(&self, uuid: Uuid) -> Option<&Path>
Tries to get a path associated with the given resource UUID.
Sourcepub fn uuid_to_path_buf(&self, uuid: Uuid) -> Option<PathBuf>
pub fn uuid_to_path_buf(&self, uuid: Uuid) -> Option<PathBuf>
Same as Self::uuid_to_path, but returns PathBuf instead of &Path.
Sourcepub fn path_to_uuid(&self, path: &Path) -> Option<Uuid>
pub fn path_to_uuid(&self, path: &Path) -> Option<Uuid>
Tries to find a UUID that corresponds for the given path.
Sourcepub fn is_registered(&self, path: &Path) -> bool
pub fn is_registered(&self, path: &Path) -> bool
Checks if the path is registered in the resource registry.
Sourcepub async fn scan(
resource_io: Arc<dyn ResourceIo>,
loaders: Arc<Mutex<RawMutex, ResourceLoadersContainer>>,
root: impl AsRef<Path>,
excluded_folders: HashSet<PathBuf, BuildHasherDefault<FxHasher>>,
) -> BTreeMap<Uuid, PathBuf>
pub async fn scan( resource_io: Arc<dyn ResourceIo>, loaders: Arc<Mutex<RawMutex, ResourceLoadersContainer>>, root: impl AsRef<Path>, excluded_folders: HashSet<PathBuf, BuildHasherDefault<FxHasher>>, ) -> BTreeMap<Uuid, PathBuf>
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
impl Clone for ResourceRegistry
Source§fn clone(&self) -> ResourceRegistry
fn clone(&self) -> ResourceRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ResourceRegistry
impl !RefUnwindSafe for ResourceRegistry
impl Send for ResourceRegistry
impl Sync for ResourceRegistry
impl Unpin for ResourceRegistry
impl UnsafeUnpin for ResourceRegistry
impl !UnwindSafe for ResourceRegistry
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
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>. Box<dyn Any> can
then be further downcast into Box<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>. Rc<Any> 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> 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> DowncastSync for T
impl<T> DowncastSync for T
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> 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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.