<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aditya Verma</title>
    <description>The latest articles on DEV Community by Aditya Verma (@aditya_verma_22).</description>
    <link>https://dev.to/aditya_verma_22</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4068717%2F533e4c85-af96-4359-aba2-6d78318ac647.png</url>
      <title>DEV Community: Aditya Verma</title>
      <link>https://dev.to/aditya_verma_22</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aditya_verma_22"/>
    <language>en</language>
    <item>
      <title>Common Programming Concepts - Part 2 (Data Types)</title>
      <dc:creator>Aditya Verma</dc:creator>
      <pubDate>Sun, 16 Aug 2026 13:20:31 +0000</pubDate>
      <link>https://dev.to/aditya_verma_22/common-programming-concepts-part-2-data-types-f5c</link>
      <guid>https://dev.to/aditya_verma_22/common-programming-concepts-part-2-data-types-f5c</guid>
      <description>&lt;h2&gt;
  
  
  What are Data Types?
&lt;/h2&gt;

&lt;p&gt;As we discussed in the last article that we can store any data in variables. The variables that we were declaring till now did not have any data types mentioned and were being assigned data type according to the data they contain by the Rust compiler. This is necessary because every data type requires a specific amount of space which is assigned after the data type is known.&lt;/p&gt;

&lt;p&gt;There are 2 basic types of data types, Scalar and Compound. We will go deep into the types a little later. In Rust the data types are statically typed, meaning that they are needed at compilation. So either we can mention the type explicitly which is called type annotation or the Rust compiler can infer the type itself in simple cases. For example, if we declare a simple number it can be inferred easily like &lt;code&gt;let num = 22&lt;/code&gt; , but if we have a more complex operation like taking a string and converting it into number then we would have to annotate the variable with the type. It will look like : &lt;code&gt;let num : u32 = "22".parse().expect("Not a number!")&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;For now don’t worry about the &lt;code&gt;.parse()&lt;/code&gt; or &lt;code&gt;.expect()&lt;/code&gt; , we focus on &lt;code&gt;: u32&lt;/code&gt; this is where we are giving the variable a type of unsigned 32 bit integer. We will discuss more about these types later in this article. As we saw in the above example we annotate a variable with its type using a &lt;code&gt;:&lt;/code&gt; . We add the &lt;code&gt;:&lt;/code&gt;  after the variable name followed by the type we want the variable to be.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scalar Types
&lt;/h3&gt;

&lt;p&gt;Scalar Types are the types that represent a single value, like a number or a character. In Rust there are 4 types of scalar data types : Integers, Floating-point numbers, Booleans and Characters. Let’s start with the easier ones and then go to the confusing types.&lt;/p&gt;

&lt;h4&gt;
  
  
  Character Type
&lt;/h4&gt;

&lt;p&gt;The Character Type represents a single Unicode Value like an ‘&lt;em&gt;a&lt;/em&gt;’ or a ‘&lt;em&gt;=’&lt;/em&gt; or an emoji like ‘🦀’. All these single values are characters. In Rust we use the &lt;code&gt;char&lt;/code&gt; keyword to declare a character type. It is 4 bytes in size. For example, if we want to declare a variable ‘&lt;em&gt;ch&lt;/em&gt;’ with the character data type we will do it like : &lt;code&gt;let ch: char = 'a';&lt;/code&gt; . This will declare a character variable called &lt;em&gt;ch&lt;/em&gt; containing the character ‘a’.&lt;/p&gt;

&lt;h4&gt;
  
  
  Boolean Type
&lt;/h4&gt;

&lt;p&gt;Boolean type is very useful data type used to denote just two values, either &lt;code&gt;true&lt;/code&gt;  or &lt;code&gt;false&lt;/code&gt; . It is 1 byte in size. It is mostly used in conditional statements to determine if some statement is true or false. We declare a boolean like : &lt;code&gt;let flag: bool = true;&lt;/code&gt; . This will create a variable flag with the data type boolean and the values as true.&lt;/p&gt;

&lt;h4&gt;
  
  
  Integer Type
&lt;/h4&gt;

&lt;p&gt;Now coming to the little complex data types, first we have Integer. Integer type is used to represent numbers without any fraction component in Rust. At first it sounds simple, we have a number either positive or negative and we assign it the type integer. But here is where the complexity and optimization in Rust comes in. Since the numbers are infinite and can get bigger to any size we cannot have a single type that is able to contain the least possible and the most possible number as it will be a waste of space. So that is why in Integers we have different types for different sizes. Furthermore we have 2 variants for all the sizes, that are : &lt;strong&gt;&lt;em&gt;signed&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;unsigned&lt;/em&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Signed integers will contain both positive and negative numbers while the unsigned integers will only contain positive numbers. So we use unsigned when we are sure that there is no possible negative value for that variable otherwise we use signed. &lt;/p&gt;

&lt;p&gt;Now that we know about why it is complex and why there are so many types let’s look at the list of all types and sizes of integers:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Length&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Signed&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Unsigned&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;8-bit&lt;/td&gt;
&lt;td&gt;i8&lt;/td&gt;
&lt;td&gt;u8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16-bit&lt;/td&gt;
&lt;td&gt;i16&lt;/td&gt;
&lt;td&gt;u16&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32-bit&lt;/td&gt;
&lt;td&gt;i32&lt;/td&gt;
&lt;td&gt;u32&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;64-bit&lt;/td&gt;
&lt;td&gt;i64&lt;/td&gt;
&lt;td&gt;u64&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;128-bit&lt;/td&gt;
&lt;td&gt;i128&lt;/td&gt;
&lt;td&gt;u128&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Architecture-dependant&lt;/td&gt;
&lt;td&gt;isize&lt;/td&gt;
&lt;td&gt;usize&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here all the types are self explanatory but let me break it down. So we put an &lt;code&gt;i&lt;/code&gt;  followed by the size of integer for signed integer and an &lt;code&gt;u&lt;/code&gt;  followed by the size of the integer for unsigned integer. And as for the last one it depends on the architecture type of the machine that we are using, so if we are using a 32-bit machine then &lt;code&gt;isize and usize&lt;/code&gt; will be 32 bit, and if we are using a 64-bit machine then &lt;code&gt;isize and usize&lt;/code&gt; will be 64 bit in size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Integer Overflow :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While we are at this topic we should also learn about a very common error that we will definitely encounter when using integers, it is called Integer Overflow. It is a condition when we try to assign a value to an integer variable that is out of range from its defined size. For example &lt;code&gt;u8&lt;/code&gt; can store values from 0-255, so if we try to assign 256 to a &lt;code&gt;u8&lt;/code&gt; variable it will throw an error.&lt;/p&gt;

&lt;p&gt;Rust handles it in 2 ways. First is if we are in debug mode Rust will panic and throw an error that looks like :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ cargo run
   Compiling programming-basics v0.1.0 &lt;span class="o"&gt;(&lt;/span&gt;&amp;lt;path&amp;gt;/programming-basics&lt;span class="o"&gt;)&lt;/span&gt;
error: this arithmetic operation will overflow
 &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; src/main.rs:3:17
  |
3 |     &lt;span class="nb"&gt;let &lt;/span&gt;m: u8 &lt;span class="o"&gt;=&lt;/span&gt; n + 1&lt;span class="p"&gt;;&lt;/span&gt;
  |                 ^^^^^ attempt to compute &lt;span class="sb"&gt;`&lt;/span&gt;u8::MAX + 1_u8&lt;span class="sb"&gt;`&lt;/span&gt;, which would overflow
  |
  &lt;span class="o"&gt;=&lt;/span&gt; note: &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="c"&gt;#[deny(arithmetic_overflow)]` on by default&lt;/span&gt;

error: could not compile &lt;span class="sb"&gt;`&lt;/span&gt;programming-basics&lt;span class="sb"&gt;`&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;bin &lt;span class="s2"&gt;"programming-basics"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; due to 1 previous error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see it clearly tells us that the number n+1 is out of the range of &lt;code&gt;u8&lt;/code&gt;  data type as in the code I assigned the value 255 to n and tried to make the variable m = n+1.&lt;/p&gt;

&lt;p&gt;Second is if we are compiling the program in release mode, then these checks are ignored. Rust will silently just ‘&lt;em&gt;wrap around&lt;/em&gt;’ the value, so like if the values was 256 then it will turn to 0 and if it was 257 it will turn to 1. &lt;/p&gt;

&lt;h4&gt;
  
  
  Floating-point Type
&lt;/h4&gt;

&lt;p&gt;To put is plainly, floating-point numbers are the numbers that contain a decimal. Meaning they contain an integer with a fraction. There are just 2 types of floating-point variables : &lt;code&gt;f32&lt;/code&gt;  and &lt;code&gt;f64&lt;/code&gt; , which are 32-bit and 64-bit respectively.&lt;/p&gt;

&lt;p&gt;This is how we represent it in code : &lt;code&gt;let fl: f32 = 2.22;&lt;/code&gt; . This will create a variable named fl and assign the value 2.22 to it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Code Implementation
&lt;/h4&gt;

&lt;p&gt;Now that we know about all the scalar data types, let us implement all of them and observe the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;number2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am an unsigned integer : {number}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am a signed integer : {number2}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;fl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;f32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;2.22&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am a floating point number : {fl}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;char&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;'🦀'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am a character : {ch}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am a boolean : {t}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ cargo run
   Compiling programming-basics v0.1.0 &lt;span class="o"&gt;(&lt;/span&gt;&amp;lt;path&amp;gt;/programming-basics&lt;span class="o"&gt;)&lt;/span&gt;
    Finished &lt;span class="sb"&gt;`&lt;/span&gt;dev&lt;span class="sb"&gt;`&lt;/span&gt; profile &lt;span class="o"&gt;[&lt;/span&gt;unoptimized + debuginfo] target&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;0.26s
     Running &lt;span class="sb"&gt;`&lt;/span&gt;target/debug/programming-basics&lt;span class="sb"&gt;`&lt;/span&gt;
22
21
I am an unsigned integer : 1234
I am a signed integer : &lt;span class="nt"&gt;-1234&lt;/span&gt;
I am a floating point number : 2.22
I am a character : 🦀
I am a boolean : &lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see it ran perfectly and the output is as expected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compound Types
&lt;/h3&gt;

&lt;p&gt;Compound Types are the data types that can group multiple values into once single type. There are 2 types of Compound Types in Rust : Tuples and Arrays. &lt;/p&gt;

&lt;p&gt;Before diving deep into these types we need to address one thing, that is you might be expecting to see String here in the Compound Types but the thing is String in Rust is a dynamic heap allocated type that does not have a fixed size, hence it is not included in this article. It deserves its own article that we will have later in this series when we are covering collections.&lt;/p&gt;

&lt;h4&gt;
  
  
  Tuple Type
&lt;/h4&gt;

&lt;p&gt;A Tuple in Rust is a way of grouping multiple values with different data types into one single compound type. Tuples have a fixed size and we cannot increase or decrease their size once declared. We create a tuple by writing the values separated by commas &lt;code&gt;,&lt;/code&gt; inside parentheses&lt;code&gt;()&lt;/code&gt; . Each value in a tuple can have its own type, they do not have to be all same or all different. By default Rust is able to detect the types in a tuple but it is still a good practise to annotate the types while declaring.&lt;/p&gt;

&lt;p&gt;The syntax to create a tuple is as follows :&lt;/p&gt;

&lt;p&gt;Without type annotation:&lt;br&gt;
&lt;code&gt;let tup = (22, false, 'a', 2.22);&lt;/code&gt;&lt;br&gt;
With type annotation:&lt;br&gt;
&lt;code&gt;let tup: (i32, bool, char, f32) = (22, false, 'a', 2.22);&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Now after creating a tuple, the question comes on how do we access these values. In Rust there are 2 ways to access these values : &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Destructuring : This way we destructure a tuple into multiple variables. It can be done using the following syntax : &lt;code&gt;let (a, b, c, d) = tup;&lt;/code&gt; . Considering the values in the above initiated tuple a will contain 22, b will contain false, c will contain ‘a’ and d will contain 2.22.&lt;/li&gt;
&lt;li&gt;Indexing : If we don’t want to create multiple variables we can directly access the values using their index or position in the tuple. We access it by writing the tuple name followed by a &lt;code&gt;.&lt;/code&gt;  and then the index we want to access. The indexes always start from 0 and not 1. So if we want to print the first element we will write : 
&lt;code&gt;let value = tup.0;&lt;/code&gt;
&lt;code&gt;println!("First element of tuple is : {value}")&lt;/code&gt; . This will print the element at 0th index meaning 1st position.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Array Type
&lt;/h4&gt;

&lt;p&gt;An Array is also a way to group multiple values into a single compound type. The catch here is that unlike tuples all the values in an array should have the same data type. We create an array by writing the values separated by commas&lt;code&gt;,&lt;/code&gt; inside square brackets&lt;code&gt;[]&lt;/code&gt; . Arrays in Rust have a fixed length and cannot be expanded or shrunk after declaration.&lt;/p&gt;

&lt;p&gt;The syntax to create an array is as follows : &lt;/p&gt;

&lt;p&gt;Without type annotation:&lt;br&gt;
&lt;code&gt;let arr = [1,2,3,4,5];&lt;/code&gt; &lt;br&gt;
With type annotation:&lt;br&gt;
&lt;code&gt;let arr: [i32; 5] = [1,2,3,4,5];&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here without the type annotation is straight forward but with the annotation after we write the name of the array we follow it by a &lt;code&gt;:&lt;/code&gt; and then square brackets&lt;code&gt;[]&lt;/code&gt; , inside which we first write the type of all the values in the array(&lt;code&gt;i32&lt;/code&gt;in our case) then a semicolon &lt;code&gt;;&lt;/code&gt; , followed by the number of values inside the array.&lt;/p&gt;

&lt;p&gt;We can also create an array with the same values by writing the values followed by a semicolon and then the number of elements.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let arr = ['a'; 5]&lt;/code&gt; , here the value of ‘arr’ will be : &lt;code&gt;['a', 'a', 'a', 'a', 'a']&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;To access the elements of an array we have one method, that is using the indexes.&lt;/p&gt;

&lt;p&gt;We access an element at an index by writing the array name followed by the index inside square brackets&lt;code&gt;[]&lt;/code&gt; . &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
If we take an array ‘arr’.&lt;br&gt;
&lt;code&gt;let arr: [i32; 5] = [1,2,3,4,5];&lt;/code&gt; &lt;br&gt;
Now we want to access and print the element at 3rd index, that is the 4th position, which contains the values 4.&lt;br&gt;
&lt;code&gt;let value = arr[3];&lt;/code&gt;&lt;br&gt;
&lt;code&gt;println!("The value at 4th position / 3rd index is : {value}");&lt;/code&gt; &lt;br&gt;
This is going to print the value &lt;strong&gt;4.&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Code Implementation
&lt;/h4&gt;

&lt;p&gt;Let’s implement and add these data types to our earlier code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;number2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am an unsigned integer : {number}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am a signed integer : {number2}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;fl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;f32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;2.22&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am a floating point number : {fl}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;char&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;'🦀'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am a character : {ch}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am a boolean : {t}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;tup&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;f32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;char&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tup&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;val1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tup&lt;/span&gt;&lt;span class="na"&gt;.2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The value of b is : {b}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The value at 3rd position / 2nd index of tuple is : {val1}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;char&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sc"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'b'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'c'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'d'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'e'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;val2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The value at 3rd position / 2nd index is : {val2}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ cargo run
   Compiling programming-basics v0.1.0 &lt;span class="o"&gt;(&lt;/span&gt;&amp;lt;path&amp;gt;/programming-basics&lt;span class="o"&gt;)&lt;/span&gt;
    Finished &lt;span class="sb"&gt;`&lt;/span&gt;dev&lt;span class="sb"&gt;`&lt;/span&gt; profile &lt;span class="o"&gt;[&lt;/span&gt;unoptimized + debuginfo] target&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;0.06s
     Running &lt;span class="sb"&gt;`&lt;/span&gt;target/debug/programming-basics&lt;span class="sb"&gt;`&lt;/span&gt;
22
21
I am an unsigned integer : 1234
I am a signed integer : &lt;span class="nt"&gt;-1234&lt;/span&gt;
I am a floating point number : 2.22
I am a character : 🦀
I am a boolean : &lt;span class="nb"&gt;true
&lt;/span&gt;The value of b is : 2.22
The value at 3rd position / 2nd index of tuple is : a
The value at 3rd position / 2nd index is : c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can see that we correctly get the value in the tuple as well as the array.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;So this article has been a big one and we learnt a lot. We learnt about Scalar and Compound types. We then went deeper and learnt which data types come under them like integer, floating-point, boolean, character, tuple and array. With this much information please don’t forget to keep practicing these types and come back to the article if you ever forget some. That is it for this one will see you all in the next article where we will explore one of the most important topic that we will cover that is “Functions”.&lt;/p&gt;

&lt;p&gt;-Aditya&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>rust</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Common Programming Concepts - Part 1 (Variables and Mutability)</title>
      <dc:creator>Aditya Verma</dc:creator>
      <pubDate>Sat, 15 Aug 2026 11:55:18 +0000</pubDate>
      <link>https://dev.to/aditya_verma_22/common-programming-concepts-part-1-variables-and-mutability-470b</link>
      <guid>https://dev.to/aditya_verma_22/common-programming-concepts-part-1-variables-and-mutability-470b</guid>
      <description>&lt;h2&gt;
  
  
  What are we covering in this article?
&lt;/h2&gt;

&lt;p&gt;As we established in the last article, “we are all nerds”. So this section might just be a revision for your basic programming concepts, and if you don’t know some then this is a great learning opportunity. This will also lay the foundation for all upcoming articles and all Rust specific concepts as well, so we need to make sure that these are very clear to us.&lt;/p&gt;

&lt;p&gt;We will be covering the basics like Variables and Mutability, Data Types, Functions, Comments and Control Flow. These topics are large so we will split this topic into 4 parts that will be divided into 4 articles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables and Mutability
&lt;/h2&gt;

&lt;p&gt;Variables in simple language are just containers that stores a type of value. When we need a value at any step we get that value using the variable name in which we stored the value. For example, if we need to store the number &lt;em&gt;22&lt;/em&gt;, we will create a variable with a name and assign that value to it. So in this case let’s say I choose the name &lt;em&gt;num&lt;/em&gt;, I will assign &lt;code&gt;num = 22&lt;/code&gt;. This way whenever I need the value &lt;em&gt;22&lt;/em&gt;, I will use &lt;em&gt;num&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Now that we are clear in what a variable is let’s talk about &lt;em&gt;mutability&lt;/em&gt;. Mutability is a very important concept in Rust as it adds an important layer to the whole security and control aspect of Rust. Mutability in plain english means the ability to change. Meaning that if something can change then it is &lt;em&gt;mutable&lt;/em&gt; and if it cannot then it is &lt;em&gt;immutable&lt;/em&gt;. In Rust all variables are immutable by default meaning once we assign a value to them we cannot change that value.&lt;/p&gt;

&lt;p&gt;Now that we are clear with both the concepts let’s see how we can create and use variables in Rust. To create a variable we use the keyword &lt;code&gt;let&lt;/code&gt; to tell Rust that we will be creating a variable. It is then followed by the name of the variable which in our example is num, so it becomes &lt;br&gt;
&lt;code&gt;let num&lt;/code&gt; . Then we write &lt;em&gt;=&lt;/em&gt; to assign it a value followed by the value, &lt;code&gt;let num = 22&lt;/code&gt; . We have just declared a variable called num and assigned it the value 22. Now we know that by default variables are immutable so if we ever want to change the value of &lt;em&gt;num&lt;/em&gt; we cannot. To change this we are given a keyword called &lt;code&gt;mut&lt;/code&gt; . This keyword when used while creating a variable makes it mutable. So if we added it to our declaration from before like &lt;code&gt;let mut num = 22&lt;/code&gt; , then we would be able to change the value of num whenever we want. &lt;/p&gt;
&lt;h3&gt;
  
  
  Seeing it in action
&lt;/h3&gt;

&lt;p&gt;That’s a lot of talking, let’s see it in action in code. We will also see how the error looks for if we try to change the variable without using &lt;code&gt;mut&lt;/code&gt; . I created a new cargo project for this section. So we start by doing &lt;code&gt;cargo new programming-basics&lt;/code&gt; . Then we go to &lt;code&gt;/programming-basics/src/main.rs&lt;/code&gt;  and we code there.&lt;/p&gt;

&lt;p&gt;Here first we simply try to declare a variable and print it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ cargo run
   Compiling programming-basics v0.1.0 &lt;span class="o"&gt;({&lt;/span&gt;path&lt;span class="o"&gt;}&lt;/span&gt;/programming-basics&lt;span class="o"&gt;)&lt;/span&gt;
    Finished &lt;span class="sb"&gt;`&lt;/span&gt;dev&lt;span class="sb"&gt;`&lt;/span&gt; profile &lt;span class="o"&gt;[&lt;/span&gt;unoptimized + debuginfo] target&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;0.09s
     Running &lt;span class="sb"&gt;`&lt;/span&gt;target/debug/programming-basics&lt;span class="sb"&gt;`&lt;/span&gt;
22
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Checking the error
&lt;/h3&gt;

&lt;p&gt;Now we try to mutate the variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we try to &lt;code&gt;cargo run&lt;/code&gt; this we get the following output in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ cargo run
   Compiling programming-basics v0.1.0 &lt;span class="o"&gt;({&lt;/span&gt;path&lt;span class="o"&gt;}&lt;/span&gt;/programming-basics&lt;span class="o"&gt;)&lt;/span&gt;
error[E0384]: cannot assign twice to immutable variable &lt;span class="sb"&gt;`&lt;/span&gt;num&lt;span class="sb"&gt;`&lt;/span&gt;
 &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; src/main.rs:4:5
  |
2 |     &lt;span class="nb"&gt;let &lt;/span&gt;num &lt;span class="o"&gt;=&lt;/span&gt; 22&lt;span class="p"&gt;;&lt;/span&gt;
  |         &lt;span class="nt"&gt;---&lt;/span&gt; first assignment to &lt;span class="sb"&gt;`&lt;/span&gt;num&lt;span class="sb"&gt;`&lt;/span&gt;
3 |     println!&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{num}"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
4 |     num &lt;span class="o"&gt;=&lt;/span&gt; 21&lt;span class="p"&gt;;&lt;/span&gt;
  |     ^^^^^^^^ cannot assign twice to immutable variable
  |
&lt;span class="nb"&gt;help&lt;/span&gt;: consider making this binding mutable
  |
2 |     &lt;span class="nb"&gt;let &lt;/span&gt;mut num &lt;span class="o"&gt;=&lt;/span&gt; 22&lt;span class="p"&gt;;&lt;/span&gt;
  |         +++

For more information about this error, try &lt;span class="sb"&gt;`&lt;/span&gt;rustc &lt;span class="nt"&gt;--explain&lt;/span&gt; E0384&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
error: could not compile &lt;span class="sb"&gt;`&lt;/span&gt;programming-basics&lt;span class="sb"&gt;`&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;bin &lt;span class="s2"&gt;"programming-basics"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; due to 1 previous error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This error clearly states that we ‘cannot assign twice to immutable variable num’.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making it mutable
&lt;/h3&gt;

&lt;p&gt;Now we try making the variable mutable and running the same program again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ cargo run
   Compiling programming-basics v0.1.0 &lt;span class="o"&gt;({&lt;/span&gt;path&lt;span class="o"&gt;}&lt;/span&gt;/programming-basics&lt;span class="o"&gt;)&lt;/span&gt;
    Finished &lt;span class="sb"&gt;`&lt;/span&gt;dev&lt;span class="sb"&gt;`&lt;/span&gt; profile &lt;span class="o"&gt;[&lt;/span&gt;unoptimized + debuginfo] target&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;0.13s
     Running &lt;span class="sb"&gt;`&lt;/span&gt;target/debug/programming-basics&lt;span class="sb"&gt;`&lt;/span&gt;
22
21
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can clearly see the reassignment of value worked without any error. We first print a 22 but after changing the value when we print we get a 21. This is the &lt;code&gt;mut&lt;/code&gt; keyword playing its part perfectly!&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Let’s end it here for now. We learnt what a variable is and what is mutability. Then we learnt about the mutability of variables in Rust and how can we implement them in code. We also learnt how we can change the mutability of a variable. Next article we learn about data types, see you all then!&lt;/p&gt;

</description>
      <category>rust</category>
      <category>variables</category>
      <category>programming</category>
      <category>mutability</category>
    </item>
    <item>
      <title>CARGO: Rust's Package Manager (Think npm or pip)</title>
      <dc:creator>Aditya Verma</dc:creator>
      <pubDate>Sun, 09 Aug 2026 16:08:53 +0000</pubDate>
      <link>https://dev.to/aditya_verma_22/cargo-rusts-package-manager-think-npm-or-pip-1k9d</link>
      <guid>https://dev.to/aditya_verma_22/cargo-rusts-package-manager-think-npm-or-pip-1k9d</guid>
      <description>&lt;h2&gt;
  
  
  Building a CARGO Project
&lt;/h2&gt;

&lt;p&gt;In the last article we learnt how we create a new CARGO project using the &lt;code&gt;cargo new&lt;/code&gt; command in the command line. Now it’s time to build that project. We will have a &lt;code&gt;main.rs&lt;/code&gt; in the &lt;code&gt;/src&lt;/code&gt; folder that was created when we executed the &lt;code&gt;cargo new&lt;/code&gt; command. It contains code for basic ‘Hello, World!’ program that we build in the last article. Let us use that as a base for now, we will code later on.&lt;/p&gt;

&lt;p&gt;Before building the project let us first understand what the term ‘&lt;em&gt;building&lt;/em&gt;’ means? So the code that we wrote is in a human readable format. Now to convert this code into a machine understandable code and then into an executable that can run directly we ‘&lt;em&gt;build’&lt;/em&gt; the project. So to lay it out plainly we build our program from a cluster of &lt;code&gt;.rs&lt;/code&gt; files into a single &lt;code&gt;.exe&lt;/code&gt; file (if we are on Windows, on Linux and on Mac they will be different) that will run our code and we do not need to compile it every time.&lt;/p&gt;

&lt;p&gt;Now that we are a little clear on what building a project is let us move to actually building our cargo project. To build a cargo project we need to run the &lt;code&gt;cargo build&lt;/code&gt; command in the new folder that was created when we ran the &lt;code&gt;cargo new&lt;/code&gt; command. In my example I named the project as ‘&lt;em&gt;cargo_intro&lt;/em&gt;’, so I will do &lt;code&gt;cd cargo_intro&lt;/code&gt; and then &lt;code&gt;cargo build&lt;/code&gt; . This will create an executable file in the &lt;code&gt;./target/debug&lt;/code&gt; folder with the same name as the project which in my case is ‘&lt;em&gt;cargo_intro&lt;/em&gt;’.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;cargo_intro
&lt;span class="nv"&gt;$ &lt;/span&gt;cargo build
   Compiling cargo_intro v0.1.0 &lt;span class="o"&gt;(&lt;/span&gt;&amp;lt;folder_path&amp;gt;/cargo_intro&lt;span class="o"&gt;)&lt;/span&gt;
    Finished &lt;span class="sb"&gt;`&lt;/span&gt;dev&lt;span class="sb"&gt;`&lt;/span&gt; profile &lt;span class="o"&gt;[&lt;/span&gt;unoptimized + debuginfo] target&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;3.98s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running &lt;code&gt;cargo build&lt;/code&gt; for the first time also creates a new file at the top level called &lt;code&gt;Cargo.lock&lt;/code&gt;. This file keeps track of the exact versions of dependencies in your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running a CARGO Project
&lt;/h2&gt;

&lt;p&gt;After the build we will have an executable file ready for us to run. We can directly run it by clicking in the file explorer or finder. But since we are all nerds here we will use the terminal to run the program. We can do so by just going to the executable in our terminal, so in our example we will do something like :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;./target/debug/cargo_intro
&lt;span class="nv"&gt;$ &lt;/span&gt;Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now learning this path and running it like this seems like a hassle if I had to do it more than 3 times. Cargo has made it easy for us to not do this and instead we just run &lt;code&gt;cargo run&lt;/code&gt; and it will run the executable for us. Another use of this command is that it eliminates the build step for us. If there are any files changes it will first build and then run the executable for us. So instead of performing 2 steps, first &lt;code&gt;cargo build&lt;/code&gt;  and then &lt;code&gt;./target/debug/&amp;lt;executable_name&amp;gt;&lt;/code&gt; we simply do &lt;code&gt;cargo run&lt;/code&gt; and cargo will build and run the executable for us.&lt;/p&gt;

&lt;p&gt;For example, let’s say I change ‘Hello, World!’ to ‘Hello, my name is Aditya.’ then it should rebuild.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;cargo run
   Compiling cargo_intro v0.1.0 &lt;span class="o"&gt;(&lt;/span&gt;&amp;lt;project_path&amp;gt;/cargo_intro&lt;span class="o"&gt;)&lt;/span&gt;
    Finished &lt;span class="sb"&gt;`&lt;/span&gt;dev&lt;span class="sb"&gt;`&lt;/span&gt; profile &lt;span class="o"&gt;[&lt;/span&gt;unoptimized + debuginfo] target&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;0.36s
     Running &lt;span class="sb"&gt;`&lt;/span&gt;target/debug/cargo_intro&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;Hello, my name is Aditya.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cargo also provides us with &lt;code&gt;cargo check&lt;/code&gt; command to check if the code will compile successfully but it will not produce a new executable with the changed code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;cargo check
    Finished &lt;span class="sb"&gt;`&lt;/span&gt;dev&lt;span class="sb"&gt;`&lt;/span&gt; profile &lt;span class="o"&gt;[&lt;/span&gt;unoptimized + debuginfo] target&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;0.03s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So that is the basics for now. This much will help us setup and run rust programs. We are good to move to actual programming concepts and creating projects to understand the deeper rust concepts. Thanks a lot if you have been part of this journey till now, from the next article we will start creating some interesting programs and learn concepts. Hope to see you there!&lt;/p&gt;

&lt;p&gt;-Aditya&lt;/p&gt;

</description>
      <category>rust</category>
      <category>cargo</category>
      <category>coding</category>
      <category>packagemanager</category>
    </item>
    <item>
      <title>Learn Rust with me 🦀</title>
      <dc:creator>Aditya Verma</dc:creator>
      <pubDate>Sat, 08 Aug 2026 11:23:14 +0000</pubDate>
      <link>https://dev.to/aditya_verma_22/learn-rust-with-me-265o</link>
      <guid>https://dev.to/aditya_verma_22/learn-rust-with-me-265o</guid>
      <description>&lt;h2&gt;
  
  
  Why Rust?
&lt;/h2&gt;

&lt;p&gt;Before starting this series and my articles related to Rust I should address why am I even trying to learn and program in Rust. Honestly the first and most important reason is I feel like doing it, that doesn’t mean I do not have a better reason. It’s just a rush of learning something new making mistakes and growing my knowledge and my skillset. Also I feel like the path that I am taking as a software developer has a pretty good spot for Rust. Actually that’s it, I cannot wait to see if Rust can make me fall in love with it or just be another language in my skillset!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note :&lt;/strong&gt; For now I am following the official - The Rust Programming Language book.&lt;/p&gt;




&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Rust is a multi-purpose system programming language. It is designed for performance, thread safety and memory safety. It provides low level control like C or C++ and provide modern features like many modern programming languages. &lt;/p&gt;

&lt;h3&gt;
  
  
  Rust Compiler : &lt;code&gt;rustc&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Rust uses the &lt;code&gt;rustc&lt;/code&gt; compiler that is written in Rust itself. It directly compiles the code to machine code. So for example if we create a file called &lt;code&gt;hello.rs&lt;/code&gt;  we can directly use the Rust compiler to compile this file and it will provide us with an executable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rustc hello.rs
./hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fun Fact :&lt;/strong&gt; While researching on this topic I got to know that Rust was very much inspired by OCaml and the very first Rust compiler was written in OCaml which then enabled to make a Rust based compiler.&lt;/p&gt;

&lt;h3&gt;
  
  
  First Program
&lt;/h3&gt;

&lt;p&gt;We create a Rust file giving it a file extension of &lt;code&gt;.rs&lt;/code&gt;. In Rust we go by the basic rule of creating a &lt;code&gt;main&lt;/code&gt; function that becomes the entry point for our application. We start by creating a &lt;code&gt;main&lt;/code&gt;  function that will be ran when we run the executable that is created after compiling the file.&lt;br&gt;
For this example we will go the traditional route and create a “Hello, World!” program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// hello.rs file.&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above is a simple Rust code to print “Hello, World!” in the terminal. Here we have a simple &lt;code&gt;main&lt;/code&gt;  function which we can define using the keyword &lt;code&gt;fn&lt;/code&gt; . Then inside the &lt;code&gt;main&lt;/code&gt; function we have a &lt;code&gt;println!&lt;/code&gt; . It is a macro according to the official guide book that is still to be explored by me. Basically if we have a &lt;code&gt;!&lt;/code&gt;  after the name it is a macro and if it’s not there it’s a function.&lt;/p&gt;

&lt;p&gt;Now we will see how we can manually compile and run the script like in the above section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;rustc hello.rs
&lt;span class="nv"&gt;$ &lt;/span&gt;./hello
&lt;span class="nv"&gt;$ &lt;/span&gt;Hello, World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  CARGO : The level up!
&lt;/h2&gt;

&lt;p&gt;Now since we have seen how can we manually compile a Rust program let’s do one thing, let’s not just use it anytime and start using Cargo! Okay so you see like in every other language we have some sort of a package manager/build system, that’s basically Cargo for Rust. It is a package manager and a build system that is used to download the libraries/dependencies that are needed in our project, build those dependencies, build the project and run it. &lt;/p&gt;

&lt;p&gt;To get started with a project using cargo we will use the &lt;code&gt;cargo new &amp;lt;project_name&amp;gt;&lt;/code&gt;  command. It will create a basic project structure and some configuration files. Let’s first explore the file structure then look at how to actually use cargo properly. When we run the &lt;code&gt;cargo new&lt;/code&gt; command we are presented with this type of file structure :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;- &amp;lt;project_name&amp;gt;/
    - Cargo.toml
    - .gitignore
    - src/
        - main.rs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay so here &lt;code&gt;.gitignore&lt;/code&gt;  contains only one thing that is the &lt;code&gt;/target&lt;/code&gt; directory since that is the build directory that we will explore later. &lt;code&gt;.gitignore&lt;/code&gt; is created since Cargo automatically initialises git for us. Next we have the &lt;code&gt;Cargo.toml&lt;/code&gt; file that we can relate to &lt;code&gt;package.json&lt;/code&gt; in JavaScript. It contains the configurations for the project including the package versions and the dependency list. And at the last we have a &lt;code&gt;src/&lt;/code&gt; folder that contains the &lt;code&gt;main.rs&lt;/code&gt; file that will start with when Cargo is used to build the project.&lt;/p&gt;

&lt;p&gt;That is it for this article! We will explore CARGO deeply in the next article. Hope you all have a wonderful day ahead of you.&lt;/p&gt;

&lt;p&gt;-Aditya&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>programming</category>
      <category>rust</category>
    </item>
  </channel>
</rss>
