Learning Rust - Common Programming Concepts

Based on “The Rust Programming” Variables and Mutability Constant are like immutable varibles, but always immutable. declare constants using the const keyword, and the type of the value must be annotated. constants can be declared in any scope, including the global scope. constants may be set only to a constant expression, not the result of a value that could only be computed at runtime. Rust’s naming convention for constants is to use all uppercase with underscores between words, such as THREE_HOURS_IN_SECONDS the compiler is able to evaluate a limited set of operations at compile time, which lets us choose to write out this value in a way that’s easier to understand and verify Shadow is different from a variable marked as mut will get a compile-time error if we accidentally try to reassign to this variable without using the let keyword....

May 30, 2022 00:00 · 9 min · ledisthebest

Learning Rust - Programming a Guessing Game

Based on “The Rust Programming” Programming a Guessing Game rust has a few things that will be imported automatically into every rust program, called prelude use use statment bring items into program that are not included in prelude use let statement to create a variable; variables are immutable in rust by default, add mut before variable name :: in String::new() indicated new is an function associated with String type. if library io hasn’t been inported with use std::io at the beginning of the program, you could still use the function with std::io::stdin...

Feb 2, 2022 00:00 · 4 min · ledisthebest

Learning Rust - Getting Started

Based on “The Rust Programming” Hello, World! Rust indent with four spaces, not a tab. println! is a Rust Macro, println is without the ! is a function. Compile it with rustc filename, similar to GCC and Clang. Hello, Cargo! Create a new cargo project with cargo new project_name. It will also initialize a Git repo, Git files won’t be generated if running within an existing Git repo. Building new project, run cargo build in project’s main directory....

Jan 29, 2022 00:00 · 1 min · ledisthebest