带有库和二进制文件的 Rust 包?

问题描述

Tok:tmp doug$ du -a

8   ./Cargo.toml
8   ./src/bin.rs
8   ./src/lib.rs
16  ./src

货物.toml:

[package]
name = "mything"
version = "0.0.1"
authors = ["me <me@gmail.com>"]

[lib]
name = "mylib"
path = "src/lib.rs"

[[bin]]
name = "mybin"
path = "src/bin.rs"

src/lib.rs:

pub fn test() {
    println!("Test");
}

src/bin.rs:

extern crate mylib; // not needed since Rust edition 2018

use mylib::test;

pub fn main() {
    test();
}

解决方法

我想制作一个 Rust 包,其中包含一个可重用的库(大部分程序都在其中实现),以及一个使用它的可执行文件。

假设我没有混淆 Rust 模块系统中的任何语义,我的Cargo.toml文件应该是什么样的?