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: 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>
source§impl<R> FromReflect for Persistent<R>where
String: FromReflect,
StorageFormat: FromReflect,
Storage: FromReflect,
Option<R>: FromReflect,
Option<Box<R>>: FromReflect,
bool: FromReflect,
R: TypePath + Resource + Serialize + DeserializeOwned,
impl<R> FromReflect for Persistent<R>where String: FromReflect, StorageFormat: FromReflect, Storage: FromReflect, Option<R>: FromReflect, Option<Box<R>>: FromReflect, bool: FromReflect, R: TypePath + Resource + Serialize + DeserializeOwned,
source§fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
Self
from a reflected value.§fn take_from_reflect(
reflect: Box<dyn Reflect, Global>
) -> Result<Self, Box<dyn Reflect, Global>>
fn take_from_reflect( reflect: Box<dyn Reflect, Global> ) -> Result<Self, Box<dyn Reflect, Global>>
Self
using,
constructing the value using from_reflect
if that fails. Read moresource§impl<R> GetTypeRegistration for Persistent<R>where
String: FromReflect,
StorageFormat: FromReflect,
Storage: FromReflect,
Option<R>: FromReflect,
Option<Box<R>>: FromReflect,
bool: FromReflect,
R: TypePath + Resource + Serialize + DeserializeOwned,
impl<R> GetTypeRegistration for Persistent<R>where String: FromReflect, StorageFormat: FromReflect, Storage: FromReflect, Option<R>: FromReflect, Option<Box<R>>: FromReflect, bool: FromReflect, R: TypePath + Resource + Serialize + DeserializeOwned,
fn get_type_registration() -> TypeRegistration
source§impl<R> Reflect for Persistent<R>where
String: FromReflect,
StorageFormat: FromReflect,
Storage: FromReflect,
Option<R>: FromReflect,
Option<Box<R>>: FromReflect,
bool: FromReflect,
R: TypePath + Resource + Serialize + DeserializeOwned,
impl<R> Reflect for Persistent<R>where String: FromReflect, StorageFormat: FromReflect, Storage: FromReflect, Option<R>: FromReflect, Option<Box<R>>: FromReflect, bool: FromReflect, R: TypePath + Resource + Serialize + DeserializeOwned,
source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
TypeInfo
] of the type represented by this value. Read moresource§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any
.source§fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
source§fn as_reflect(&self) -> &dyn Reflect
fn as_reflect(&self) -> &dyn Reflect
source§fn as_reflect_mut(&mut self) -> &mut dyn Reflect
fn as_reflect_mut(&mut self) -> &mut dyn Reflect
source§fn clone_value(&self) -> Box<dyn Reflect>
fn clone_value(&self) -> Box<dyn Reflect>
Reflect
trait object. Read moresource§fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
source§fn reflect_owned(self: Box<Self>) -> ReflectOwned
fn reflect_owned(self: Box<Self>) -> ReflectOwned
source§fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
source§impl<R> Struct for Persistent<R>where
String: FromReflect,
StorageFormat: FromReflect,
Storage: FromReflect,
Option<R>: FromReflect,
Option<Box<R>>: FromReflect,
bool: FromReflect,
R: TypePath + Resource + Serialize + DeserializeOwned,
impl<R> Struct for Persistent<R>where String: FromReflect, StorageFormat: FromReflect, Storage: FromReflect, Option<R>: FromReflect, Option<Box<R>>: FromReflect, bool: FromReflect, R: TypePath + Resource + Serialize + DeserializeOwned,
source§fn field(&self, name: &str) -> Option<&dyn Reflect>
fn field(&self, name: &str) -> Option<&dyn Reflect>
name
as a &dyn Reflect
.source§fn field_mut(&mut self, name: &str) -> Option<&mut dyn Reflect>
fn field_mut(&mut self, name: &str) -> Option<&mut dyn Reflect>
name
as a
&mut dyn Reflect
.source§fn field_at(&self, index: usize) -> Option<&dyn Reflect>
fn field_at(&self, index: usize) -> Option<&dyn Reflect>
index
as a
&dyn Reflect
.source§fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
index
as a &mut dyn Reflect
.source§fn name_at(&self, index: usize) -> Option<&str>
fn name_at(&self, index: usize) -> Option<&str>
index
.source§fn iter_fields(&self) -> FieldIter<'_>
fn iter_fields(&self) -> FieldIter<'_>
source§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
].source§impl<R> TypePath for Persistent<R>where
String: FromReflect,
StorageFormat: FromReflect,
Storage: FromReflect,
Option<R>: FromReflect,
Option<Box<R>>: FromReflect,
bool: FromReflect,
R: TypePath + Resource + Serialize + DeserializeOwned,
impl<R> TypePath for Persistent<R>where String: FromReflect, StorageFormat: FromReflect, Storage: FromReflect, Option<R>: FromReflect, Option<Box<R>>: FromReflect, bool: FromReflect, R: TypePath + Resource + Serialize + DeserializeOwned,
source§fn type_path() -> &'static str
fn type_path() -> &'static str
source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
source§impl<R> Typed for Persistent<R>where
String: FromReflect,
StorageFormat: FromReflect,
Storage: FromReflect,
Option<R>: FromReflect,
Option<Box<R>>: FromReflect,
bool: FromReflect,
R: TypePath + Resource + Serialize + DeserializeOwned,
impl<R> Typed for Persistent<R>where String: FromReflect, StorageFormat: FromReflect, Storage: FromReflect, Option<R>: FromReflect, Option<Box<R>>: FromReflect, bool: FromReflect, R: TypePath + Resource + Serialize + DeserializeOwned,
impl<R: Resource + Serialize + DeserializeOwned> Resource for Persistent<R>where Self: Send + Sync + 'static,
Auto Trait Implementations§
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§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist.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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
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
.§fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§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.§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.