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§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>
],
while immutable components will instead have [Component<Mutability = Immutable>
]. Read moreSource§fn register_required_components(
requiree: ComponentId,
components: &mut ComponentsRegistrator<'_>,
required_components: &mut RequiredComponents,
inheritance_depth: u16,
recursion_check_stack: &mut Vec<ComponentId>,
)
fn register_required_components( requiree: ComponentId, components: &mut ComponentsRegistrator<'_>, required_components: &mut RequiredComponents, inheritance_depth: u16, recursion_check_stack: &mut Vec<ComponentId>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn register_component_hooks(hooks: &mut ComponentHooks)
fn register_component_hooks(hooks: &mut ComponentHooks)
Component::on_add
, etc.)ComponentHooks
.Source§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper
. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component
, this is populated by annotating fields containing entities with #[entities]
Read moreSource§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 ComponentsRegistrator<'_>, ids: &mut impl FnMut(ComponentId), )
Source§fn register_required_components(
components: &mut ComponentsRegistrator<'_>,
required_components: &mut RequiredComponents,
)
fn register_required_components( components: &mut ComponentsRegistrator<'_>, required_components: &mut RequiredComponents, )
Bundle
.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<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
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<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components( self, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
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 more