pub struct ModeSwitcher { /* private fields */ }Expand description
Handles mode transitions with context preservation
The ModeSwitcher is responsible for:
- Validating mode transitions
- Preserving context across switches
- Restoring context after switches
- Managing mode-specific data
Implementations§
Source§impl ModeSwitcher
impl ModeSwitcher
Sourcepub fn new(context: ModeContext) -> Self
pub fn new(context: ModeContext) -> Self
Create a new mode switcher with the given context
Sourcepub fn register_mode(&mut self, mode: Arc<dyn Mode>)
pub fn register_mode(&mut self, mode: Arc<dyn Mode>)
Register a mode
Sourcepub async fn current_mode_id(&self) -> Option<String>
pub async fn current_mode_id(&self) -> Option<String>
Get the current mode ID
Sourcepub async fn switch_mode(&self, mode_id: &str) -> Result<Arc<dyn Mode>>
pub async fn switch_mode(&self, mode_id: &str) -> Result<Arc<dyn Mode>>
Switch to a different mode with context preservation
This method:
- Validates the mode exists
- Saves the current context if switching from a mode
- Restores the saved context for the new mode if available
- Creates a fresh context if the mode hasn’t been visited before
- Updates the current mode
Sourcepub async fn context(&self) -> ModeContext
pub async fn context(&self) -> ModeContext
Get the current context
Sourcepub async fn update_context<F>(&self, f: F) -> Result<()>where
F: FnOnce(&mut ModeContext),
pub async fn update_context<F>(&self, f: F) -> Result<()>where
F: FnOnce(&mut ModeContext),
Update the context with a closure
Sourcepub async fn save_context_for_mode(&self, mode_id: &str) -> Result<()>
pub async fn save_context_for_mode(&self, mode_id: &str) -> Result<()>
Save the current context for a specific mode
Sourcepub async fn restore_context_for_mode(&self, mode_id: &str) -> Result<()>
pub async fn restore_context_for_mode(&self, mode_id: &str) -> Result<()>
Restore context for a specific mode
Sourcepub fn mode_count(&self) -> usize
pub fn mode_count(&self) -> usize
Get the number of registered modes
Sourcepub fn list_mode_ids(&self) -> Vec<String>
pub fn list_mode_ids(&self) -> Vec<String>
Get all registered mode IDs
Sourcepub async fn has_saved_context(&self, mode_id: &str) -> bool
pub async fn has_saved_context(&self, mode_id: &str) -> bool
Check if context is saved for a mode
Sourcepub async fn saved_context_count(&self) -> usize
pub async fn saved_context_count(&self) -> usize
Get the number of saved contexts
Sourcepub async fn clear_saved_contexts(&self)
pub async fn clear_saved_contexts(&self)
Clear all saved contexts
Auto Trait Implementations§
impl Freeze for ModeSwitcher
impl !RefUnwindSafe for ModeSwitcher
impl Send for ModeSwitcher
impl Sync for ModeSwitcher
impl Unpin for ModeSwitcher
impl !UnwindSafe for ModeSwitcher
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