Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

crate-module/crate #335

giscus[bot] bot announced in Book Comments
Nov 30, 2022 · 9 comments · 4 replies
Discussion options

crate-module/crate

Learning Rust By Practice, narrowing the gap between beginner and skilled-dev with challenging examples, exercises and projects.

https://zh.practice.rs/crate-module/crate.html

You must be logged in to vote

Replies: 9 comments 4 replies

Comment options

完成一个 Package 同时拥有 src/main.rs 和 src/lib.rs ,要怎么cargo new 呢?

You must be logged in to vote
1 reply
Comment options

cargo new 之后手动新建 lib.rsmain.rs

Comment options

还是不太明白。 我们可以用cargo new 简单地新建一个 package,里面会有一个默认的main.rs,也就是同名的crate。 但是package里面可以包含若干个 crate,那么我如何通过 cargo在这个package里面新建新的 crate 呢?

You must be logged in to vote
3 replies
Comment options

同问

Comment options

手动创建吧

Comment options

your_package/
├── Cargo.toml
├── src/
 ├── main.rs // 默认的二进制crate入口
 ├── bin/
 ├── another_binary.rs // 新的二进制crate
Comment options

lala

You must be logged in to vote
0 replies
Comment options

done

You must be logged in to vote
0 replies
Comment options

mark finished

You must be logged in to vote
0 replies
Comment options

cargo new hello-package // 创建项目 binary package
cargo new hello-package1 --lib // 创建项目和lib.rs,library crate
You must be logged in to vote
0 replies
Comment options

done

You must be logged in to vote
0 replies
Comment options

该目录下的每个文件都是一个独立的二进制包,包名与文件名相同,不再与 package 的名称相同。

所以"包名"的用处是什么呢?调用不同模块里那些函数,填地址的时候,注重的是"模块名"吧?这个包名我们有办法在哪里看到,或者在哪里用到吗?

You must be logged in to vote
0 replies
Comment options

done.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /