pub struct WorldManager { /* private fields */ }Expand description
Manages World state with concurrent access support.
WorldManager owns the World and processes state modifications
through a command queue. This enables multiple ChannelRunners
to modify the World without holding locks.
§Thread Safety
- Reads: Via
Arc<RwLock<World>>clone (parallel reads allowed) - Writes: Via command queue (sequential, no contention)
§Example
ⓘ
let (manager, cmd_tx) = WorldManager::new();
// Clone for read access
let world_read = manager.world();
// Spawn the manager loop
tokio::spawn(manager.run());
// Send commands
cmd_tx.send(WorldCommand::Kill { id, reason }).await?;Implementations§
Source§impl WorldManager
impl WorldManager
Sourcepub fn new() -> (Self, WorldCommandSender)
pub fn new() -> (Self, WorldCommandSender)
Sourcepub fn with_world(world: World) -> (Self, WorldCommandSender)
pub fn with_world(world: World) -> (Self, WorldCommandSender)
Creates a WorldManager with an existing World.
Use this when you need to initialize the World before starting the manager (e.g., creating the IO channel).
§Example
ⓘ
let mut world = World::new();
let io = world.create_channel(ChannelConfig::interactive());
let (manager, cmd_tx) = WorldManager::with_world(world);Sourcepub fn world(&self) -> Arc<RwLock<World>>
pub fn world(&self) -> Arc<RwLock<World>>
Returns a clone of the World handle for read access.
The returned Arc<RwLock<World>> can be shared across tasks
for concurrent read access.
Sourcepub async fn run(self)
pub async fn run(self)
Runs the command processing loop.
This method consumes the manager and runs until:
- A
Shutdowncommand is received - All command senders are dropped (channel closed)
§Example
ⓘ
let (manager, cmd_tx) = WorldManager::new();
let handle = tokio::spawn(manager.run());
// ... use cmd_tx ...
cmd_tx.send(WorldCommand::Shutdown).await?;
handle.await?;Auto Trait Implementations§
impl Freeze for WorldManager
impl !RefUnwindSafe for WorldManager
impl Send for WorldManager
impl Sync for WorldManager
impl Unpin for WorldManager
impl UnsafeUnpin for WorldManager
impl !UnwindSafe for WorldManager
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
Mutably borrows from an owned value. Read more