Book Rust by Example ⬆
This repository gathers Rust code examples from the online book "Rust by Example" (RBE). It also includes several batch files for experimenting with Rust on a Windows machine. |
This example has the following directory structure :
> tree /a /f . | findstr /v /b [A-Z] | build.bat | Cargo.toml | rustfmt.toml \---src main.rs
Command cargo run
executes the Rust program main.rs
:
> cargo clean & cargo run Compiling _01_Display v1.0.0 (R:\rust-by-example\01_Display) Finished dev [unoptimized + debuginfo] target(s) in 2.81s Running `target\debug\main.exe` Compare structures: Display: (0, 14) Debug: MinMax(0, 14) The big range is (-300, 300) and the small is (-3, 3) Compare points: Display: x: 3.3, y: 7.2 Debug: Point2D { x: 3.3, y: 7.2 }
This example has the following directory structure :
> tree /a /f . | findstr /v /b [A-Z] | build.bat | Cargo.toml \---src main.rs
Command build run
executes the Rust program main.rs
:
> build -verbose clean run Compile 1 Rust source file to directory "target" Dublin: 53.348°N 6.260°W Oslo: 59.950°N 10.750°E Vancouver: 49.250°N 123.100°W Color { red: 128, green: 255, blue: 90 } Color { red: 0, green: 3, blue: 254 } Color { red: 0, green: 0, blue: 0 }
This example has the following directory structure :
> tree /a /f . | findstr /v /b [A-Z] | build.bat | Cargo.toml \---src main.rs
Command build run
executes the Rust program main.rs
:
> build -verbose clean run Delete directory "target" Compile 1 Rust source files to directory "target" Hello World!
Command cargo run
executes the Rust program main.rs
:
> cargo clean & cargo run Removed 0 files Compiling _01_HelloWorld v1.0.0 (L:\rust-by-example\01_HelloWorld) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s Running `target\debug\main.exe` Hello World!
02_Literals
Example ▴
This example has the following directory structure :
> tree /a /f . | findstr /v /b [A-Z] | build.bat | Cargo.toml \---src main.rs
Command cargo run
executes the Rust program main.rs
:
> cargo clean && cargo run Compiling _02_Primitives v1.0.0 (R:\rust-by-example\02_Literals) Finished dev [unoptimized + debuginfo] target(s) in 2.53s Running `target\debug\main.exe` 1 + 2 = 3 1 - 2 = -1 true AND false is false true OR false is true NOT true is false 0011 AND 0101 is 0001 0011 OR 0101 is 0111 0011 XOR 0101 is 0110 1 << 5 is 32 0x80 >> 2 is 0x20 One million is written as 1000000
> tree /a /f . | findstr /v /b [A-Z] | build.bat | Cargo.toml \---src main.rs
Command build run
executes the Rust program main.rs
:
> build -verbose clean run Compile 1 Rust source files to directory "target" [...] warning: value assigned to `mutable` is never read --> R:\rust-by-example\02_Primitives\src\main.rs:27:5 | 27 | mutable = true as i32; | ^^^^^^^ | = help: maybe it is overwritten before being read? warning: 4 warnings emitted inferred_type: 4294967296 mutable: true