vault backup: 2025-02-17 16:15:54
This commit is contained in:
parent
389dc210cd
commit
f29d3f1789
@ -0,0 +1,28 @@
|
|||||||
|
# First things first
|
||||||
|
Chapter 1 takes you through an introduction to rustc -- an older version of compiling and running rust that predates Cargo. The first thing I did was create a 'Hello, world!' program.
|
||||||
|
|
||||||
|
I also learned that when naming files, the convention is underscores:
|
||||||
|
|
||||||
|
**Good**:
|
||||||
|
hello_world.rs
|
||||||
|
|
||||||
|
**Bad**:
|
||||||
|
helloworld.rs
|
||||||
|
|
||||||
|
# What does a Rust program look like?
|
||||||
|
|
||||||
|
Here was our full hello world program:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
First, there's the fn main() function. This is always the first piece of code that will run in a Rust program.
|
||||||
|
|
||||||
|
Second, indents always happen with 4 spaces, not a tab.
|
||||||
|
|
||||||
|
Third, the print statement is doing something a little different. It is a *macro*, not a function. Macros use ! at the end, while functions do not.
|
||||||
|
|
||||||
|
Fourth, each line ends with a semicolon. Much like C.
|
||||||
6
3-99 Research/Rust/hello_world/hello_cargo/Cargo.toml
Normal file
6
3-99 Research/Rust/hello_world/hello_cargo/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "hello_cargo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
3
3-99 Research/Rust/hello_world/hello_cargo/src/main.rs
Normal file
3
3-99 Research/Rust/hello_world/hello_cargo/src/main.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user