Shell

Struct Shell 

Source
pub struct Shell { /* private fields */ }

Implementations§

Source§

impl Shell

Source

pub fn new() -> Shell

创建一个新的 Shell 实例。

§示例
use std::collections::HashMap;
use shell_server::{Shell};

fn main() {
    let shell = Shell::new();
    // 接下来可以添加函数并使用 shell 进行操作
}
Examples found in repository?
examples/main.rs (line 37)
36fn main() {
37    let mut shell = Shell::new();
38
39    reg_shell_cmd!(shell,
40        {"hello", print_hello},
41        {"add_two", add_two},
42        {"print_str", print_str},
43        {"add_seven", add_seven},
44        {"run_exit", exit}
45    );
46
47    let pid = get_self_pid();
48
49    println!("pid: {}", pid);
50
51    match Server::new(
52        shell,
53        format!("/tmp/rust_shell_cmd_{}", pid),
54        format!("/tmp/rust_shell_output_{}", pid),
55    )
56    .run()
57    {
58        Ok(_) => (),
59        Err(err) => println!("run err: {}", err),
60    }
61}
Source

pub fn get_reg_commands(&self) -> Vec<String>

获取 shell 环境中已注册的命令列表。

§返回值

一个包含所有已注册命令名称的字符串向量。

Source

pub fn reg_func(&mut self, name: String, addr: u64)

向 shell 环境中注册一个函数。

§参数
  • name: 要注册的函数的名称。
  • addr: 要注册的函数的地址。
Source

pub fn run_command(&self, command_line: &String) -> Result<(), String>

运行 shell 环境中的命令。

§参数
  • command_line: 要运行的命令行。
§返回值

运行命令的结果。

Trait Implementations§

Source§

impl Clone for Shell

Source§

fn clone(&self) -> Shell

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 Default for Shell

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Shell

§

impl RefUnwindSafe for Shell

§

impl Send for Shell

§

impl Sync for Shell

§

impl Unpin for Shell

§

impl UnwindSafe for Shell

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<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> 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.