YTread Logo
YTread Logo

Rust Tutorial: Data Types Explained

Apr 30, 2024
Aldo from Zero to Mastery Here in today's

tutorial

we dive into

data

types

in Rust. Now, this isn't just any

tutorial

, it's part of Jason Lin's complete Rust programming training course, which is available at Zero to Mastery Academy if you want. Learn Russ completely from scratch or simply improve your Russ skills. I recommend you check it out by clicking the link in the top right corner or check out the description below for the full description, of course, okay, that's it for me. I pass it on to Jason. Enjoy this video. We'll take a look at the fundamental

data

types

.
rust tutorial data types explained
I'll explain what data types are and we'll go over some examples now before we dive into the type of data we need. to take a step back and see how computers store data now computers store data in binary format and that is a one or a zero and anything can be represented using ones and zeros which could be anything whether it be images, sounds, words now. When we write a program, we don't have to worry about ones and zeros, we're not going to spam ones and zeros all the time, the computer is actually going to translate it for us, so when we write a program, we'll be representing the program using words that we understand and then it will be translated into ones and zeros that the computer understands and there are some types of data and one type of data would be like a number or a word, those can be types of data. and some of them are useful in all programs all the time and the useful ones are provided by Rust itself and we will see them below, now that we are not limited only to the ones that he provides, we can put them. together to create richer data types, which we will do throughout the course, so here are the basic data types.
rust tutorial data types explained

More Interesting Facts About,

rust tutorial data types explained...

We have a boolean that is true or false, so the boolean can be true or false. The booleans are really important because we will be test conditions like if something is true then run this code and if it is false then we run another code so that the boolean values ​​are all over the place then we have integers and those will be integers they can be positive or negative, there are some limits to integers which we will cover on the next slide, we have doubles or floats and these would be floating point numbers and it is called floating point because we have this decimal here, which is the point and it can float between decimals very long. like this or short like 0 below we have one character and one character is a single letter, so the uppercase a is one character.
rust tutorial data types explained
Lowe C is also a character and if we put the number six, if we use the single quotes, that will give us the image. representation of the number six, so the actual number six itself is different from the visual representation of the number six, that's a big thing and it might be a little confusing at first, but as you write more programs it will become much clearer later. continuation. string and a string are just several characters put together to create a word, so when we want to have a string we use double quotes. So hello, it's a string, we can put the word string as a string, we can have sentences, we can have numbers, anything you want.
rust tutorial data types explained
Putting the double quotes will render as you see on the screen. Now integers are a special case because they have different sizes available because sometimes you only need a few numbers and other times you need a lot of numbers, so we have several different types of integers to facilitate this. Here is a list of all the integer types that are available in the standard library. The i8 and u8 are signed so I means signed and signed means we can have a negative sign so the range for an I8 is 128 up to 127 so if you ever work with data and just If you need 20 or 30 inputs, you can choose I8 or u8 because that is all the memory you would need to store 20 or 30 inputs. and if we look down here, for example, on I64, this number I don't even know how to say, but it's huge and if you only had to store 20 things, you don't want to use that much memory just to store the 20 things because you have capacity or so many things, so it is important to choose the correct integer type based on the numbers you are going to work with and I am not going to detail each one, you can just pause the video and watch each one or if you want and it is also in the documentation, a special case is the I and uze size, so these sizes actually change depending on where the program is compiled, so if we are compiling on a 32-bit system, then this I measure and use, it will be these here i32 and u32.
If we are compiling it on a more modern system that is 64 bit, then it will be an I64 or u64 and let's say you are working on a microcontroller. code like let's say you have a drone flight controller and you only have a little bit of memory, maybe those are an I8 or an i16, so these will change depending on where the program is actually compiled, okay let's recap so we can represent any data type with binary and we as programmers don't necessarily need to understand what binary code is, we just need to be able to represent it using human terms like words and numbers, and

rust

is going to convert it for us the basic data types are boolean which are true and false integers double and float integers which are decimal numbers characters which are a single character and string which is a string of characters put together and when we work with numbers I want to choose a number size that is appropriate for the data set we are using and that's a summary of the data types in Rust.
Many thanks to Jason for this interesting tutorial. If you enjoyed this short snippet, imagine what you can learn in its entirety. Rust Programming Boot Camp Course, which again you can find in the top right corner and in the description below. Don't forget to subscribe and hit the notification bell so you never miss other future tutorials from Jason and other experts. zero to master the re instructors keep coding, keep learning and see you next time

If you have any copyright issue, please Contact