pub struct CommandScope<'a, S = ()> { /* private fields */ }Expand description
命令处理器的窄上下文:暴露 shell/树/生命周期/参数,不暴露 wgpu/winit。
S 是应用持有的命令状态类型,默认 () 保持 0.6 的无状态用法。类型化状态由
CommandScope::with_state 显式注入;CommandScope::new 只构造 S = ()
的兼容上下文,不提供 app_state_mut()。
Implementations§
Source§impl<'a> CommandScope<'a, ()>
impl<'a> CommandScope<'a, ()>
Sourcepub fn new(
shell: &'a dyn WindowShell,
tree: &'a mut ElementTree,
lifecycle: Option<&'a FeatureLifecycle>,
args: &'a [String],
source: CommandSource,
needs_redraw: Option<&'a mut bool>,
needs_rebuild: Option<&'a mut bool>,
) -> Self
pub fn new( shell: &'a dyn WindowShell, tree: &'a mut ElementTree, lifecycle: Option<&'a FeatureLifecycle>, args: &'a [String], source: CommandSource, needs_redraw: Option<&'a mut bool>, needs_rebuild: Option<&'a mut bool>, ) -> Self
构造无状态命令上下文。needs_redraw / needs_rebuild 可为 None:
自定义 RunnerApp 没有这两个标志时,按 CommandOutcome 自行调用 ctx.request_redraw()。
Source§impl<'a, S> CommandScope<'a, S>
impl<'a, S> CommandScope<'a, S>
Sourcepub fn with_state(
shell: &'a dyn WindowShell,
tree: &'a mut ElementTree,
lifecycle: Option<&'a FeatureLifecycle>,
args: &'a [String],
source: CommandSource,
needs_redraw: Option<&'a mut bool>,
needs_rebuild: Option<&'a mut bool>,
app_state: &'a mut S,
) -> Self
pub fn with_state( shell: &'a dyn WindowShell, tree: &'a mut ElementTree, lifecycle: Option<&'a FeatureLifecycle>, args: &'a [String], source: CommandSource, needs_redraw: Option<&'a mut bool>, needs_rebuild: Option<&'a mut bool>, app_state: &'a mut S, ) -> Self
构造带类型化应用状态的命令上下文。状态所有权在 App 层,这里只借可变引用。
Sourcepub fn app_state_mut(&mut self) -> &mut S
pub fn app_state_mut(&mut self) -> &mut S
命令处理器访问类型化应用状态。无状态上下文调用会 panic,调用方必须先确认
自己注册的是 CommandRouter<S> 且由 with_state 投递。
pub fn try_app_state_mut(&mut self) -> Option<&mut S>
pub fn shell(&self) -> &dyn WindowShell
pub fn tree_mut(&mut self) -> &mut ElementTree
pub fn lifecycle(&self) -> Option<&FeatureLifecycle>
pub fn source(&self) -> CommandSource
pub fn request_redraw(&mut self)
pub fn request_rebuild(&mut self)
Auto Trait Implementations§
impl<'a, S = ()> !RefUnwindSafe for CommandScope<'a, S>
impl<'a, S = ()> !Send for CommandScope<'a, S>
impl<'a, S = ()> !Sync for CommandScope<'a, S>
impl<'a, S = ()> !UnwindSafe for CommandScope<'a, S>
impl<'a, S> Forget for CommandScope<'a, S>
impl<'a, S> Freeze for CommandScope<'a, S>where
&'a dyn WindowShell: Freeze,
&'a mut ElementTree: Freeze,
&'a FeatureLifecycle: Freeze,
&'a [String]: Freeze,
&'a mut bool: Freeze,
&'a mut S: Freeze,
impl<'a, S> Move for CommandScope<'a, S>
impl<'a, S> Unpin for CommandScope<'a, S>where
&'a dyn WindowShell: Unpin,
&'a mut ElementTree: Unpin,
&'a FeatureLifecycle: Unpin,
&'a [String]: Unpin,
&'a mut bool: Unpin,
&'a mut S: Unpin,
impl<'a, S> UnsafeUnpin for CommandScope<'a, S>where
&'a dyn WindowShell: UnsafeUnpin,
&'a mut ElementTree: UnsafeUnpin,
&'a FeatureLifecycle: UnsafeUnpin,
&'a [String]: UnsafeUnpin,
&'a mut bool: UnsafeUnpin,
&'a mut S: UnsafeUnpin,
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