-
Notifications
You must be signed in to change notification settings - Fork 1.1k
crate-module/crate #335
-
crate-module/crate
Learning Rust By Practice, narrowing the gap between beginner and skilled-dev with challenging examples, exercises and projects.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 3 -
👎 1 -
🎉 2 -
❤️ 1 -
🚀 1 -
👀 1
Replies: 9 comments 4 replies
-
完成一个 Package 同时拥有 src/main.rs 和 src/lib.rs ,要怎么cargo new 呢?
Beta Was this translation helpful? Give feedback.
All reactions
-
cargo new 之后手动新建 lib.rs
或 main.rs
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 5
-
还是不太明白。 我们可以用cargo new 简单地新建一个 package,里面会有一个默认的main.rs,也就是同名的crate。 但是package里面可以包含若干个 crate,那么我如何通过 cargo在这个package里面新建新的 crate 呢?
Beta Was this translation helpful? Give feedback.
All reactions
-
同问
Beta Was this translation helpful? Give feedback.
All reactions
-
手动创建吧
Beta Was this translation helpful? Give feedback.
All reactions
-
your_package/ ├── Cargo.toml ├── src/ ├── main.rs // 默认的二进制crate入口 ├── bin/ ├── another_binary.rs // 新的二进制crate
Beta Was this translation helpful? Give feedback.
All reactions
-
lala
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
mark finished
Beta Was this translation helpful? Give feedback.
All reactions
-
cargo new hello-package // 创建项目 binary package
cargo new hello-package1 --lib // 创建项目和lib.rs,library crate
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
该目录下的每个文件都是一个独立的二进制包,包名与文件名相同,不再与 package 的名称相同。
所以"包名"的用处是什么呢?调用不同模块里那些函数,填地址的时候,注重的是"模块名"吧?这个包名我们有办法在哪里看到,或者在哪里用到吗?
Beta Was this translation helpful? Give feedback.
All reactions
-
done.
Beta Was this translation helpful? Give feedback.