pub struct StorageWorld { /* private fields */ }Expand description
World that reads/writes individual entities from Soroban persistent storage.
Only dirty state is written back on flush(). Entities must be explicitly
loaded before they can be queried or modified.
Implementations§
Source§impl StorageWorld
impl StorageWorld
Sourcepub fn load_metadata(env: &Env) -> Self
pub fn load_metadata(env: &Env) -> Self
Load world metadata from persistent storage.
If no metadata exists, creates a fresh world.
Sourcepub fn load_entity(
&mut self,
env: &Env,
entity_id: EntityId,
) -> Result<(), CougrError>
pub fn load_entity( &mut self, env: &Env, entity_id: EntityId, ) -> Result<(), CougrError>
Load a single entity’s component list and component data from storage.
Sourcepub fn load_entities(
&mut self,
env: &Env,
entity_ids: &[EntityId],
) -> Result<(), CougrError>
pub fn load_entities( &mut self, env: &Env, entity_ids: &[EntityId], ) -> Result<(), CougrError>
Load multiple entities from storage.
Sourcepub fn spawn_entity(&mut self, env: &Env) -> EntityId
pub fn spawn_entity(&mut self, env: &Env) -> EntityId
Spawn a new entity (assigns ID but doesn’t write to storage until flush).
Sourcepub fn add_component(
&mut self,
env: &Env,
entity_id: EntityId,
component_type: Symbol,
data: Bytes,
)
pub fn add_component( &mut self, env: &Env, entity_id: EntityId, component_type: Symbol, data: Bytes, )
Add a component to an entity.
Sourcepub fn get_component(
&self,
entity_id: EntityId,
component_type: &Symbol,
) -> Option<Bytes>
pub fn get_component( &self, entity_id: EntityId, component_type: &Symbol, ) -> Option<Bytes>
Get a component’s data from loaded state.
Sourcepub fn has_component(
&self,
entity_id: EntityId,
component_type: &Symbol,
) -> bool
pub fn has_component( &self, entity_id: EntityId, component_type: &Symbol, ) -> bool
Check if a loaded entity has a component.
Sourcepub fn remove_component(
&mut self,
entity_id: EntityId,
component_type: &Symbol,
) -> bool
pub fn remove_component( &mut self, entity_id: EntityId, component_type: &Symbol, ) -> bool
Remove a component from an entity.
Sourcepub fn despawn_entity(&mut self, entity_id: EntityId)
pub fn despawn_entity(&mut self, entity_id: EntityId)
Despawn an entity, removing all its components.
Sourcepub fn flush(&mut self, env: &Env)
pub fn flush(&mut self, env: &Env)
Flush all dirty state to Soroban persistent storage.
Only writes entries that have been modified since the last flush.
Sourcepub fn next_entity_id(&self) -> EntityId
pub fn next_entity_id(&self) -> EntityId
Returns the next entity ID.
Sourcepub fn entity_count(&self) -> u32
pub fn entity_count(&self) -> u32
Returns the number of live entities.
Sourcepub fn entity_ids(&self) -> &Vec<EntityId>
pub fn entity_ids(&self) -> &Vec<EntityId>
Returns all known entity IDs from metadata.
Sourcepub fn to_simple_world(&self, env: &Env) -> SimpleWorld
pub fn to_simple_world(&self, env: &Env) -> SimpleWorld
Convert loaded state to a SimpleWorld.
Useful for running systems that expect SimpleWorld.
Sourcepub fn from_simple_world(world: &SimpleWorld, env: &Env) -> Self
pub fn from_simple_world(world: &SimpleWorld, env: &Env) -> Self
Create a StorageWorld from a SimpleWorld (for migration).
Marks everything as dirty so the next flush() writes all state.
Auto Trait Implementations§
impl Freeze for StorageWorld
impl !RefUnwindSafe for StorageWorld
impl !Send for StorageWorld
impl !Sync for StorageWorld
impl Unpin for StorageWorld
impl UnsafeUnpin for StorageWorld
impl !UnwindSafe for StorageWorld
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<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W), ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>
Source§impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X), ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>
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> 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