Struct keeshond_datapack::DataStore
source · [−]pub struct DataStore<T: DataObject + 'static> { /* private fields */ }
Expand description
Storage that allows lookup and access of DataObjects of a given type
Implementations
sourceimpl<T: DataObject + 'static> DataStore<T>
impl<T: DataObject + 'static> DataStore<T>
sourcepub fn new(source_manager: Rc<RefCell<SourceManager>>) -> DataStore<T>
pub fn new(source_manager: Rc<RefCell<SourceManager>>) -> DataStore<T>
Constructs a new DataStore that gets its Sources from the given SourceManager
sourcepub fn load_package(
&mut self,
package_name: &str
) -> Result<DataStoreOk, DataError>
pub fn load_package(
&mut self,
package_name: &str
) -> Result<DataStoreOk, DataError>
Loads the package by the given name if it is not already loaded.
sourcepub fn get_id(
&self,
package_name: &str,
pathname: &str
) -> Result<DataId<T>, DataError>
pub fn get_id(
&self,
package_name: &str,
pathname: &str
) -> Result<DataId<T>, DataError>
Gets the numeric ID of the DataObject from the given package at the given pathname.
sourcepub fn get_id_mut(
&mut self,
package_name: &str,
pathname: &str
) -> Result<DataId<T>, DataError>
pub fn get_id_mut(
&mut self,
package_name: &str,
pathname: &str
) -> Result<DataId<T>, DataError>
Gets the numeric ID of the DataObject from the given package at the given pathname. If the package is not loaded, it will be loaded automatically.
sourcepub fn get(&self, id: DataId<T>) -> Option<&T>
pub fn get(&self, id: DataId<T>) -> Option<&T>
Returns a reference to the DataObject by the given DataId, if one exists. Otherwise returns None.
sourcepub fn get_mut(&mut self, id: DataId<T>) -> Option<&mut T>
pub fn get_mut(&mut self, id: DataId<T>) -> Option<&mut T>
Returns a mutable reference to the DataObject by the given DataId, if one exists. Otherwise returns None.
sourcepub fn list_package_contents(&self, package_name: &str) -> Vec<String>
pub fn list_package_contents(&self, package_name: &str) -> Vec<String>
Returns a string list of the names of each DataObject in the given package. The package will need to have been loaded or this will return an empty list. Please do not call this repeatedly.
sourcepub fn unload_package(&mut self, package_name: &str) -> bool
pub fn unload_package(&mut self, package_name: &str) -> bool
Unloads the given package from memory. Any DataObjects will be dropped, but pathname-id mappings will be retained in memory so that existing references will not be invalidated. Returns true if the package was loaded.
sourcepub fn unload_all(&mut self)
pub fn unload_all(&mut self)
Unloads all packages from memory. Any DataObjects will be dropped, but pathname-id mappings will be retained in memory so that existing references will not be invalidated. Returns true if the package was loaded.
sourcepub fn unload_unused(&mut self)
pub fn unload_unused(&mut self)
Unloads all packages that do not have an active PackageUseToken.
sourcepub fn package_loaded(&self, package_name: &str) -> bool
pub fn package_loaded(&self, package_name: &str) -> bool
Returns true if the given package is loaded.
sourcepub fn package_use_token(
&self,
package_name: &str
) -> Option<PackageUseToken<T>>
pub fn package_use_token(
&self,
package_name: &str
) -> Option<PackageUseToken<T>>
Returns a PackageUseToken that can be used to keep the given package from being unloaded automatically.
sourcepub fn save(
&mut self,
package_name: &str,
pathname: &str,
source_id: SourceId
) -> Result<(), DataError>
pub fn save(
&mut self,
package_name: &str,
pathname: &str,
source_id: SourceId
) -> Result<(), DataError>
sourcepub fn reprepare(&mut self, id: DataId<T>) -> bool
pub fn reprepare(&mut self, id: DataId<T>) -> bool
Marks the DataObject by the given DataId as needing to be “reprepared”. Use this, for example, when data has been changed and it needs to be reflected in a backend via the PreparedStore. Returns true if the data was marked for reprepare, otherwise false.
sourcepub fn reload(
&mut self,
package_name: &str,
pathname: &str
) -> Result<(), DataError>
pub fn reload(
&mut self,
package_name: &str,
pathname: &str
) -> Result<(), DataError>
Reloads an already-loaded resource by the given name.
sourcepub fn load_direct(
&self,
package_name: &str,
pathname: &str,
source_id: SourceId
) -> Result<T, DataError>
pub fn load_direct(
&self,
package_name: &str,
pathname: &str,
source_id: SourceId
) -> Result<T, DataError>
Loads a single DataObject from the given source and returns it. This function does not
index, cache, or track the loaded object in any way. Loading the object through here will
result in a separate copy in memory even if it was previously loaded through the usual
package loading mechanism. For most cases you should use load_package()
or
get_id_mut()
instead.
Auto Trait Implementations
impl<T> !RefUnwindSafe for DataStore<T>
impl<T> !Send for DataStore<T>
impl<T> !Sync for DataStore<T>
impl<T> Unpin for DataStore<T> where
T: Unpin,
impl<T> !UnwindSafe for DataStore<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert 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
. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more