-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from okbug/study/rust
学习Rust的笔记
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
创建项目: | ||
|
||
`cargo new project-name` | ||
|
||
运行项目: | ||
|
||
`cargo run` | ||
|
||
或者`cargo build` | ||
build之后要在target文件夹下面运行可执行文件 | ||
|
||
## mod的概念 | ||
mod类似nodejs中的一个个本地模块 | ||
```rust | ||
// main.rs | ||
|
||
mod mod1 | ||
fn main() { | ||
println!("{}", mod1::TEXT); | ||
} | ||
|
||
// mod1.rs 或者mod1文件下下面的mod.rs文件 | ||
pub const TEXT: &str = "Hello, World"; | ||
``` | ||
|
||
使用这个办法可以在main中引入我们的mod1中的变量和方法 | ||
|