-
Book Overview & Buying
-
Table Of Contents
Rust for C++ Developers
By :
While programmers might associate our work with writing code, much of the behavior of our programs revolves around declaring data instead. Thus, we'll look at declaring and using variables and structures first. The concepts should all feel very familiar to C++ programmers, but we'll learn about the basic syntactical and behavioral quirks that separate Rust from C++.
Declaring a simple variable is straightforward in both languages. Let us first look at how this is done in Rust:
simple_variable.rs
let some_int : i32 = 0;
And next in C++:
simple_variable.cpp
const int some_int = 0;
Even with this simple example, we can immediately observe several interesting things about Rust. The let keyword introduces a name that we can use to reference a piece of data. In C++, we might call this a variable declaration, but in Rust, it's often referred to as a let binding. This keyword and terminology...