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() -> (WorldManager, Sender<WorldCommand>)
pub fn new() -> (WorldManager, Sender<WorldCommand>)
Sourcepub fn with_world(world: World) -> (WorldManager, Sender<WorldCommand>)
pub fn with_world(world: World) -> (WorldManager, Sender<WorldCommand>)
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 !RefUnwindSafe for WorldManager
impl !UnwindSafe for WorldManager
impl Freeze for WorldManager
impl Send for WorldManager
impl Sync for WorldManager
impl Unpin for WorldManager
impl UnsafeUnpin 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
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> ⓘ
Converts
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> ⓘ
Converts
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