Skip to main content

CommandScope

Struct CommandScope 

Source
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, ()>

Source

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>

Source

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 层,这里只借可变引用。

Source

pub fn app_state_mut(&mut self) -> &mut S

命令处理器访问类型化应用状态。无状态上下文调用会 panic,调用方必须先确认 自己注册的是 CommandRouter<S> 且由 with_state 投递。

Source

pub fn try_app_state_mut(&mut self) -> Option<&mut S>

Source

pub fn shell(&self) -> &dyn WindowShell

Source

pub fn tree_mut(&mut self) -> &mut ElementTree

Source

pub fn lifecycle(&self) -> Option<&FeatureLifecycle>

Source

pub fn source(&self) -> CommandSource

Source

pub fn args(&self) -> &[String]

仅 SecondInstance 携带命令行参数(不含 exe 路径),其余来源为空。

Source

pub fn request_redraw(&mut self)

Source

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>

§

impl<'a, S> Move for CommandScope<'a, S>

§

impl<'a, S> Unpin for CommandScope<'a, S>

§

impl<'a, S> UnsafeUnpin for CommandScope<'a, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>