pub struct PlanModeState { /* private fields */ }Expand description
Plan Mode 全局状态(跨工具共享)
使用单一 Mutex 保护 active + plan_file_path,避免以下并发问题:
- enter() 的 TOCTOU 竞态(先检查 is_active 再进入)
- exit() 不清理 plan_file_path
- is_active() 与 get_plan_file_path() 之间状态不一致
Implementations§
Source§impl PlanModeState
impl PlanModeState
pub fn new() -> Self
Sourcepub fn enter(&self, path: impl Into<String>) -> Result<(), String>
pub fn enter(&self, path: impl Into<String>) -> Result<(), String>
进入 plan mode,同时设置 plan 文件路径 返回 Ok(()) 表示成功进入,Err(msg) 表示已在 plan mode
Sourcepub fn get_state(&self) -> (bool, Option<String>)
pub fn get_state(&self) -> (bool, Option<String>)
原子地检查是否 active 并获取 plan 文件路径 返回 (is_active, plan_file_path)
Sourcepub fn get_plan_file_path(&self) -> Option<String>
pub fn get_plan_file_path(&self) -> Option<String>
获取 plan 文件路径(仅在 active 时有意义)
Trait Implementations§
Source§impl Debug for PlanModeState
impl Debug for PlanModeState
Auto Trait Implementations§
impl !Freeze for PlanModeState
impl RefUnwindSafe for PlanModeState
impl Send for PlanModeState
impl Sync for PlanModeState
impl Unpin for PlanModeState
impl UnsafeUnpin for PlanModeState
impl UnwindSafe for PlanModeState
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> 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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.