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. |
Example 01_Display
is organized as follows :
> 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 }
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!
02_Literals
Example ▴
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
Command cargo 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