带有库和二进制文件的 Rust 包? [英] Rust package with both a library and a binary?
本文介绍了带有库和二进制文件的 Rust 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想制作一个 Rust 包,其中包含一个可重用的库(大部分程序在其中实现),以及一个使用它的可执行文件.
I would like to make a Rust package that contains both a reusable library (where most of the program is implemented), and also an executable that uses it.
假设我没有混淆 Rust 模块系统中的任何语义,我的 Cargo.toml
文件应该是什么样的?
Assuming I have not confused any semantics in the Rust module system, what should my Cargo.toml
file look like?
推荐答案
Tok:tmp doug$ du -a
8 ./Cargo.toml
8 ./src/bin.rs
8 ./src/lib.rs
16 ./src
Cargo.toml:
Cargo.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:
src/lib.rs:
pub fn test() {
println!("Test");
}
src/bin.rs:
src/bin.rs:
extern crate mylib; // not needed since Rust edition 2018
use mylib::test;
pub fn main() {
test();
}
这篇关于带有库和二进制文件的 Rust 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文