Rust 编程语言-7-packages,crates,modu
2022-01-10 本文已影响0人
onemoremile
package
- src/main.rs 是crate的默认约定入口, 或者src/lib.rs
- 一个package由一个或多个crate组成
- 二进制程序,或者lib 库
$ cargo new my-project
Created binary (application) `my-project` package
$ ls my-project
Cargo.toml
src
$ ls my-project/src
main.rs
modules
mod front_of_house {
mod hosting {
fn add_to_waitlist() {}
fn seat_at_table() {}
}
mod serving {
fn take_order() {}
fn serve_order() {}
fn take_payment() {}
}
}
mod的例子
mod front_of_house {
mod hosting {
fn add_to_waitlist() {}
fn seat_at_table() {}
}
mod serving {
fn take_order() {}
fn serve_order() {}
fn take_payment() {}
}
}
- use
引入外部库/系统库到当前crate - pub
让当前module、方法对外可见