Struct RuntimeManager

Source
pub struct RuntimeManager<R>
where R: VmRuntime + Send + Sync + 'static,
{ /* private fields */ }
Expand description

运行时管理器

  • 🎯在一个数据结构中封装「虚拟机运行时」与「配置信息」
  • 📌只负责单个运行时的运行管理
    • 🚩不负责「终止、重启运行时」等过程

Implementations§

Source§

impl<R> RuntimeManager<R>
where R: VmRuntime + Send + Sync + 'static,

Source

pub fn new(runtime: R, config: RuntimeConfig) -> Self

构造函数

  • 🎯由此接管虚拟机实例、配置的所有权
Source

pub fn manage(&mut self) -> Result<Result<()>>

【主函数】在运行时启动后,对其进行管理

  • 🎯健壮性:更多「警告/重来」而非panic
  • 🎯用户友好:尽可能隐藏底层内容
    • 如错误堆栈
  • 📌主要逻辑
    • .nal脚本预加载
    • 用户的运行时交互
    • Websocket服务端
  • 🚩【2024-04-03 00:33:41】返回的Result作为程序的终止码
    • Ok(Ok(..)) ⇒ 程序正常终止
    • Ok(Err(..)) ⇒ 程序异常终止
    • Err(..) ⇒ 程序异常中断
Source

pub fn prelude_nal(&mut self) -> ControlFlow<Result<()>, Result<()>>

预置NAL

  • 🎯用于自动化调取.nal文件进行测试
  • 🚩【2024-04-03 10:28:18】使用ControlFlow对象以控制「是否提前返回」和「返回的结果」
    • 📌Continue => 使用「警告&忽略」的方式处理Result => 继续(用户输入/Websocket服务端)
    • 📌Break => 告知调用者「需要提前结束」
      • 📌Break => 正常退出
      • 📌Break => 异常退出(报错)
Source

pub fn spawn_read_output(&mut self) -> Result<JoinHandle<Result<()>>>

生成「读取输出」子线程

Source

pub fn try_spawn_ws_server(&mut self) -> Result<Option<JoinHandle<Result<()>>>>

生成「Websocket服务」子线程

Source

pub fn spawn_user_input(&mut self) -> Result<JoinHandle<Result<()>>>

生成「用户输入」子线程

Source

pub fn input_line_to_vm( runtime: &mut R, line: &str, config: &RuntimeConfig, output_cache: &mut OutputCache, nal_root_path: &Path, ) -> Result<()>

置入一行输入

  • 📄nal_root_path:从NAL文件加载⇒NAL文件所在路径;用户输入⇒配置文件所在路径

Trait Implementations§

Source§

impl<R> Clone for RuntimeManager<R>
where R: VmRuntime + Send + Sync + 'static + Clone,

Source§

fn clone(&self) -> RuntimeManager<R>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R> Debug for RuntimeManager<R>
where R: VmRuntime + Send + Sync + 'static + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for RuntimeManager<R>

§

impl<R> RefUnwindSafe for RuntimeManager<R>

§

impl<R> Send for RuntimeManager<R>

§

impl<R> Sync for RuntimeManager<R>

§

impl<R> Unpin for RuntimeManager<R>

§

impl<R> UnwindSafe for RuntimeManager<R>

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> BoostWithOption for T

Source§

fn option<C>(self, criterion: C) -> Option<Self>
where C: FnOnce(&Self) -> bool,

根据某条件把自身变为可选值 Read more
Source§

fn some(self) -> Option<Self>

将自身封装为Some Read more
Source§

fn none(self) -> Option<Self>

将自身封装为None 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> JoinTo for T

Source§

fn join_to<S>(self, out: &mut String, sep: impl AsRef<str>)
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个「目标字串」中,中途不创建任何辅助字符串 Read more
Source§

fn join_to_new<S>(self, sep: impl AsRef<str>) -> String
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个新字串中 Read more
Source§

fn join_to_multi<S>(self, out: &mut String, sep: &[impl AsRef<str>])
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个「目标字串」中,使用多个分隔符,中途不创建任何辅助字符串 Read more
Source§

fn join_to_multi_new<S>(self, sep: &[impl AsRef<str>]) -> String
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个新字串中,使用多个分隔符 Read more
Source§

impl<T> JoinTo for T

Source§

fn join_to<S>(self, out: &mut String, sep: impl AsRef<str>)
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个「目标字串」中,中途不创建任何辅助字符串 Read more
Source§

fn join_to_new<S>(self, sep: impl AsRef<str>) -> String
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个新字串中 Read more
Source§

fn join_to_multi<S>(self, out: &mut String, sep: &[impl AsRef<str>])
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个「目标字串」中,使用多个分隔符,中途不创建任何辅助字符串 Read more
Source§

fn join_to_multi_new<S>(self, sep: &[impl AsRef<str>]) -> String
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个新字串中,使用多个分隔符 Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToDebug for T
where T: Debug,

Source§

fn to_debug(&self) -> String

将对象转换为「用Debug格式化的字符串」

Source§

impl<T> ToDebug for T
where T: Debug,

Source§

fn to_debug(&self) -> String

将对象转换为「用Debug格式化的字符串」

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Void for T

Source§

fn void(self)

Source§

impl<T> Void for T

Source§

fn void(self)

Source§

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