Struct bevy_persistent::persistent::Persistent
source · pub struct Persistent<R: Resource + Serialize + DeserializeOwned> { /* private fields */ }
Expand description
A persistent resource.
Persistent resources are Bevy resources which are automatically synchronized with the disk.
They require a name for logging, a path to be saved to and loaded from, a storage format, and a default resource in case the persistent resource is created for the first time.
They are synchronized with the disk from the moment of their creation.
Implementations§
source§impl<R: Resource + Serialize + DeserializeOwned> Persistent<R>
impl<R: Resource + Serialize + DeserializeOwned> Persistent<R>
sourcepub fn builder() -> PersistentBuilder<R>
pub fn builder() -> PersistentBuilder<R>
Creates a persistent resource builder.
sourcepub fn new(
name: impl ToString,
format: StorageFormat,
storage: Storage,
loaded: bool,
default: R,
revertible: bool,
revert_to_default_on_deserialization_errors: bool,
) -> Result<Persistent<R>, PersistenceError>
pub fn new( name: impl ToString, format: StorageFormat, storage: Storage, loaded: bool, default: R, revertible: bool, revert_to_default_on_deserialization_errors: bool, ) -> Result<Persistent<R>, PersistenceError>
Creates a persistent resource.
§Panics
Panics if revert_to_default_on_deserialization_errors
is set to true
but revertible
is set to false
.
source§impl<R: Resource + Serialize + DeserializeOwned> Persistent<R>
impl<R: Resource + Serialize + DeserializeOwned> Persistent<R>
sourcepub fn format(&self) -> StorageFormat
pub fn format(&self) -> StorageFormat
Gets the storage format of the resource.
sourcepub fn is_revertible(&self) -> bool
pub fn is_revertible(&self) -> bool
Gets if the resource is revertible.
sourcepub fn is_unloaded(&self) -> bool
pub fn is_unloaded(&self) -> bool
Gets if the resource is unloaded.
sourcepub fn try_get_mut(&mut self) -> Option<&mut R>
pub fn try_get_mut(&mut self) -> Option<&mut R>
Tries to get the resource mutably.
source§impl<R: Resource + Serialize + DeserializeOwned> Persistent<R>
impl<R: Resource + Serialize + DeserializeOwned> Persistent<R>
sourcepub fn set(&mut self, new_resource: R) -> Result<(), PersistenceError>
pub fn set(&mut self, new_resource: R) -> Result<(), PersistenceError>
Sets the resource.
Changes are synchronized with the underlying storage immediately.
sourcepub fn update(
&mut self,
updater: impl Fn(&mut R),
) -> Result<(), PersistenceError>
pub fn update( &mut self, updater: impl Fn(&mut R), ) -> Result<(), PersistenceError>
Updates the resource.
Changes are synchronized with the underlying storage immediately.
§Panics
Panics if the resource is unloaded.
sourcepub fn unload(&mut self) -> Result<(), PersistenceError>
pub fn unload(&mut self) -> Result<(), PersistenceError>
Unloads the resource from memory.
Changes are synchronized with the underlying storage before unloading.
§Panics
Panics if the resource is unloaded.
sourcepub fn unload_without_persisting(&mut self)
pub fn unload_without_persisting(&mut self)
Unloads the resource from memory immediately.
Changes are not synchronized with the underlying storage before unloading.
sourcepub fn reload(&mut self) -> Result<(), PersistenceError>
pub fn reload(&mut self) -> Result<(), PersistenceError>
Reloads the resource from the underlying storage.
If reloading fails, the underlying resource is kept untouched.
sourcepub fn revert_to_default(&mut self) -> Result<(), PersistenceError>
pub fn revert_to_default(&mut self) -> Result<(), PersistenceError>
Reverts the resource to it’s default value.
Loaded status is kept upon reloading.
§Panics
Panics if the resource is not revertible.
sourcepub fn revert_to_default_in_memory(&mut self) -> Result<(), PersistenceError>
pub fn revert_to_default_in_memory(&mut self) -> Result<(), PersistenceError>
Reverts the resource to it’s default value only in memory, not persistent storage.
§Panics
Panics if the resource is not revertible.
source§impl<R: Resource + Serialize + DeserializeOwned> Persistent<R>
impl<R: Resource + Serialize + DeserializeOwned> Persistent<R>
Trait Implementations§
source§impl<R: Resource + Serialize + DeserializeOwned> Component for Persistent<R>
impl<R: Resource + Serialize + DeserializeOwned> Component for Persistent<R>
source§const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
source§fn register_component_hooks(_hooks: &mut ComponentHooks)
fn register_component_hooks(_hooks: &mut ComponentHooks)
ComponentHooks
.source§impl<R: Debug + Resource + Serialize + DeserializeOwned> Debug for Persistent<R>
impl<R: Debug + Resource + Serialize + DeserializeOwned> Debug for Persistent<R>
source§impl<R: Resource + Serialize + DeserializeOwned> Deref for Persistent<R>
impl<R: Resource + Serialize + DeserializeOwned> Deref for Persistent<R>
source§impl<R: Resource + Serialize + DeserializeOwned> DerefMut for Persistent<R>
impl<R: Resource + Serialize + DeserializeOwned> DerefMut for Persistent<R>
impl<R: Resource + Serialize + DeserializeOwned> Resource for Persistent<R>
Auto Trait Implementations§
impl<R> Freeze for Persistent<R>where
R: Freeze,
impl<R> RefUnwindSafe for Persistent<R>where
R: RefUnwindSafe,
impl<R> Send for Persistent<R>
impl<R> Sync for Persistent<R>
impl<R> Unpin for Persistent<R>where
R: Unpin,
impl<R> UnwindSafe for Persistent<R>where
R: UnwindSafe,
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<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
source§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
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.