在cargo.toml中添加

    1. [[bin]]
    2. name = "test"
    3. path = "src/main_test.rs"
    4. // 如果是lib
    5. [lib]
    6. name = "test"
    7. path = "src/main_lib.rs"

    运行

    1. cargo run --bin test

    设置默认运行test,在cargo.toml中添加default-run = "test"

    1. [package]
    2. name = "xmbcli"
    3. version = "0.1.0"
    4. authors = ["root"]
    5. edition = "2018"
    6. default-run = "test"


    **
    另一种方式,可以把rs文件放在src/bin目录下,运行时会自动识别,不需要再改cargo.toml

    1. cargo run --bin main_test