Getting Started with Rust (Part 2): Rust Syntax, Data Types and Control Flow Basics

Zalwert
5 min readJul 18, 2024

Rust is a systems programming language that focuses on safety, speed, and concurrency.

In this part, we will cover the very basics of syntax, variables, data types, ownership, and control flow.

Remember you can test RUST online here. This article is a continuation of the series of articles here.

Syntax and Variables

Rust’s syntax is clean and modern, making it relatively easy to pick up if you are familiar with other programming languages.

Let’s start with the simple print statement!

Example Code: Medium, rulez!

fn main() {
println!("Medium, rulez!");
}

fn is a keyword used to declare a function.

  • fn main() { ... }: This line defines a function named main. In Rust, the main function is special—it is the entry point of most Rust programs. When you run a Rust program, execution starts from the main function.
  • println!("Medium, rulez!");: Inside the main function, this line is a macro invocation (println!), not a function call. Rust distinguishes macros from functions using the ! syntax. The println! macro prints the text "Medium, rulez!" to the standard output…

--

--

Zalwert

Experienced in building data-intensive solutions for diverse industries