started book again
This commit is contained in:
8
book/guessing_game/Cargo.toml
Normal file
8
book/guessing_game/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
12
book/guessing_game/src/main.rs
Normal file
12
book/guessing_game/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use std::io;
|
||||
// file:///home/luket/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/share/doc/rust/html/std/io/index.html
|
||||
|
||||
fn main() {
|
||||
println!("guess the number");
|
||||
println!("your guess: ");
|
||||
let mut guess = String::new();
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("failed to read line");
|
||||
println!("your guess: {guess}");
|
||||
}
|
8
book/hello_cargo/Cargo.toml
Normal file
8
book/hello_cargo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "hello_cargo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
3
book/hello_cargo/src/main.rs
Normal file
3
book/hello_cargo/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
60
book/notes
Normal file
60
book/notes
Normal file
@@ -0,0 +1,60 @@
|
||||
chapter 2
|
||||
https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html
|
||||
|
||||
include packages:
|
||||
using std::io;
|
||||
|
||||
print is a macro:
|
||||
println!("text");
|
||||
|
||||
make a new mutable string:
|
||||
let mut guess = String::new();
|
||||
// new is a function of the string type.
|
||||
// an "associated function"
|
||||
|
||||
& is a reference
|
||||
|
||||
result is an enumeration
|
||||
it's variants are "Ok" and "Err"
|
||||
|
||||
|
||||
There are a set of "items" defined before importing anything. This is called the "prelude".
|
||||
|
||||
|
||||
chapter 1
|
||||
https://doc.rust-lang.org/book/ch01-00-getting-started.html
|
||||
|
||||
linux:
|
||||
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
|
||||
|
||||
update:
|
||||
rustup update
|
||||
|
||||
docs:
|
||||
rustup doc
|
||||
|
||||
compiler is `rustc`
|
||||
|
||||
cargo --version
|
||||
|
||||
toml = toms obvious minimal language
|
||||
|
||||
new project:
|
||||
cargo new $project_name --vcs=none
|
||||
|
||||
$project_dir/
|
||||
$project_dir/Cargo.toml
|
||||
$project_dir/src/main.rs
|
||||
$project_dir/target/debug/$project_bin
|
||||
|
||||
build:
|
||||
cargo build
|
||||
|
||||
run:
|
||||
cargo run
|
||||
|
||||
don't compile, just check:
|
||||
cargo check
|
||||
|
||||
don't add debug symbols:
|
||||
cargo build --release
|
Reference in New Issue
Block a user