Rust Programming 101 Full Course - Rust for Beginners
Key Takeaways
This video covers the basics of Rust programming, sponsored by Snyk, and provides resources for further learning, including a full Rust 101 course and security consulting services.
Full Transcript
what's up YouTube TCM here back with another video and today we're going to be doing a loger video teaching one of my favorite programming languages which is rust so full disclosure a lot of this course comes from the rust 101 course over on TCM Security Academy we're going to be covering the first two hours or so of 5our course you're going to get through all these fun topics here I'm just going to scroll through them but we're going to cover a lot of content all the way through this Challenge B if you're interested in learning more this is the only time we're going to pitch you you're welcome to check out the TCM Security Academy you can get access to this course and other programming courses and hacking and all other fun stuff but we'll cover more information control flow functions more challenges all kinds of more fun stuff so you get the first two hours it's a really good chunk of this course also gives you a good sample for rust hey why buy a course if you're not actually interested in Rust programming so hopefully this gets you interested in Rust it's a great programming language hopefully you'll become a rust station after this and you learn something thing from the next 2 hours we are together so we're going to stop here take a quick ad from our sponsor and then we're going to jump right into this course on [Music] Rust man why does it always feel like I'm playing catch-up with security you having trouble with your code again yeah I can't seem to keep up with all the vulnerabilities I can write all this code but fixing it man it's like running a marathon with a weight strap to my ankle man I used to feel the same way until I started using sneak but it does all the heavy lifting for you let me show you so first things first you got to go to snak.io and you can fix them with just a click watch this I come into here I can open a fix PR or a pull request and sneak opens fixed PR so you can can merge and move on plus it does it all from your existing tools idees CLI repos pipelines Docker Hub and more and look how easy that was to just do a pull request with these issues in hand it's amazingly fast so what are you waiting for come check out sneak and find out if there's any vulnerabilities within your project it's free and you can sign up using my Link at sneak thecybermentor welcome to this rust 101 course my name is Heath Adams and I will be your instructor for the entirety of this course a really quick who am I I am the CEO at TCM security we are a dual-headed organization that offers training and Consulting Services if you're watching this course it's most likely that you are on the training side of the business on the Consulting side my background is an ethical hacking we provide ethical hacking and penetration testing services as well as other Consulting and cyber Security Services on the training side we've got a lot of different courses we started out teaching ethical hacking but have branched out into blue team forensics defensive side we branched into Linux and Python and other coding courses and this fits right in with the rest of it so if you're unfamiliar with rust we'll cover that in just a second if you're interested in finding out more about me or connecting with me you're welcome to connect with me on LinkedIn Twitter welcome to follow on YouTube and twitch as well as we do live stream and we do have content on YouTube in over 500,000 subscribers at the time of this video so we'd love for you to subscribe and help get us to a million the sites below that you see you'll also see our tcm.com website that is our website for Consulting the academy is the website you're on right now and the certification site is for our certifications such as the pmpt the pcrp pgmrto by the way I hate PowerPoints this is the only time in this course you're ever going to see a PowerPoint is for the introduction outside of this it is completely Hands-On I absolutely hate doing slides so uh really quick what is rust well rust is a system programming language we can think of it as similar to C++ or even maybe even hascal and that's mostly because it's been influenced by those languages rust has its own syntax and features which make it really awesome some even compare Russ to coding languages like go and Swift because it has focused on performance and safety which is really nice and you can see it's designed to have low-level control over a system all right so we are focus on a lot of things with rust and has a lot of improvements in fact rust was created by Mozilla who makes the Firefox browser and rust was utilized to create a new version of Fire Fox which became incredibly fast and efficient and that was because of rust being used it was actually really cool the big benefits of rust are memory safety that's really number one in my opinion and that's why it's listed first because it has an ownership and borrowing system which we'll talk about in the course and it helps prevent a lot of common mistakes that developers make all right so it helps make the code more secure it's also a very performance-based programming language which is awesome it has concurrency which is really neat and also the community for Russ is fantastic you're going to see that there's documentation out there there are books written that are open source it is fantastic to find resources and information on Russ along with a lot of tools that are built out there this is a very quote unquote upand cominging language cuz it's newer but it is so awesome and it just does a lot of things that you wish you could do with some of the other languages ultimately the expressiveness helps us be more concise it allows us to be more secure allows us to avoid bugs and that is what really sets rust apart in my opinion you can do a lot of cool things with Russ and we're going to see some of that functionality in this course and with that what are the requirements for this course well all you really need is patience and willingness to learn if you've never done coding course before or learned any coding languages before that's perfectly acceptable this is a oneon-one course you're expected to know nothing on it ly and you just need a Computing environment other than that we need you to be on Windows Linux Mac whatever's fine and you should have 8 gigs of RAM if you have less than 8 gigs it's okay just ideal to have 8 gigs and 20 gigs of disc space again ideal to have 20 gigs don't really need it we're not going to create any large projects in this course with that out the way let's talk about what we will cover in this course and to do that it's probably just best to kind of scroll through the curriculum as is right now so we are going to talk about how to install rust we'll talk about creating projects hello world and comments and air handling all those things we'll talk about the different Primitives if none of this makes sense by the way don't worry about it uh at the end of each section by the way there's going to be section quizzes in here so that way you can have a test on knowledge everything in these videos is going to be Hands-On coding direct as well uh we'll cover varable we'll have different challenges along the way uh it'll get a little bit more advanced as we go so I'm not going to list out every single topic you're welcome to look at the curriculum as well but you'll see that we have different challenges as we go and then eventually we build into the very end which is going to be tying it all together and we have some projects that are in here uh one is listed as coming soon right now I do plan to add more to this course I think in its current form it's very very complete but I always am looking to add more fun items and projects things like that so at the time of this video we only have three projects but you may see more by the time you purchase this course and when this is recorded and for every item if we just go to click on a random item let's look at something like math operators here if we click on this and you'll see what the course format looks like you'll have a video in here and with the video underneath you'll have instructions or additional learning material and reading material in here as well so just depending on the video that you're on there may be more detail or less detail like for example if we look at strings looks like there's some detail in here gives you more information than just what you see in the video that way you're having different forms of learning from both video based learning and written based learning as well along with the quizzes that come with each section so the overall goal by the end of this is that you take this and you have a foundational knowledge for rust you have all these items that you learn then you start to build out projects and you have have challenges where you're forced to kind of do it on your own and see if you can put things together based on what you learn and my goal for you by the time you walk away from this is that you have a very strong Foundation that if you wanted to build upon this and go out and be a full-time rest programmer you absolutely could and that's really it I won't keep you much longer for this video I don't like really long introductions or anything like that I know you're probably anxious to get started so let's just go ahead and get started again all you need is is a machine and a desire and willingness to learn let's go jump into the next video where we talk about course support and then we'll get this ball rolling and start working with rust so I'll see you over in the next video before we dive into the course I want to make our Discord server known and available to you and this is a very very important resource okay at the time of this recording we've got 51,000 500 people in here and this is the place that you would go if you have any questions about your course now we have 247 support you can identify our team and staff here in the right hand side you can see staff admin and support again we're available 24/7 first stop when you get here please read the server rules so if you come into server make sure you read the rules understand different items understand about pinging people and things like that and just make sure you read through that so you're an upstanding citizen once you're through that you can scroll down and you can come to this St here Academy section in this St here Academy section there will be a placeholder for the rust 101 course it's a placeholder now there will be an upside down smiley face here all you have to do is click the upside down smiley face to join the private server all these servers that you see right here where it says Academy private these are course channels that you can join if you're a part of the course and what that gives you access to we'll look at an example real quick here's the pH course which just launched a couple weeks ago and you can see people are in here talking about the course about the materials asking any questions they can come in here and make suggestions about the course any items anything like that this is a great place to not only ask questions if you're having trouble but to also network with other people going through the course with you find additional resources etc etc now on top of this we also have a ton of other channels in here we've got Chann to just chat with people so off topic infos discussion but we also have channels down towards the bottom where you can talk about different foundational skills if you're in this programming course you could talk about programming we have different sections of infos that you can chat through we've got different lab areas career we've got resume help as an example job postings in here uh certification discussion even pet pictures and random stuff like that as well uh we do put on some occasional live streams and make announcements in here that are important so it's very worthwhile joining this is the only place that we offer support for our courses if you email in we're going to redirect you to the Discord Channel because we can offer support in real time and live screen with you share screen if we need to etc etc so I will link the links to the Discord in the description below I'll also show them to you very quickly so it might be a little hard to read but discord.gg TCM will take you there as will TCM M -.com Discord same place all right so you just log in come in here you can continue on join Etc right very very easy very straightforward to join and that's really it so again if you want course support this is the place to go make sure you're tracking otherwise let's go ahead and jump into getting started with this course let's talk about installing rut now installing rust is fairly straightforward if you are on Windows Mac or Linux very easy what you do is you go to the rust-lang dorg website and I'm going to put all the links in the description below by the way so just check that out if you need them but then you just go to install here and under install it'll have rust up here so you can have rust up for uh windows 32bit or 64-bit or if you are a Windows Mac or Windows subsystem for Linux user you can use this curl Command right here to install rust now if you are a Windows user let's go ahead and follow along if you're a Linux user go ahead and get this installed and then we're going to follow along as well so for Windows you can use rust up. RS and just go ahead and download this executable you will then just run the executable and follow the onscreen instructions it's really straightforward so straightforward I don't even have to show you literally just click next next next all right get them installed the other thing you're going to need as a Windows user is this Microsoft C++ build tools now go ahead and download that install that as well once you have all this installed Windows Linux Mac whatever you're going to need an IDE all right and I prefer Visual Studio code this is very very easy to work with and this is what we're going to use to the course so I highly recommend using this if you have a preferred IDE if you have have something you're familiar with already you want to use it that's fine however Visual Studio code is my goto on this website code. visual studio.com download you are going to need to download your respective installer so if you're on Windows download the windows installer Linux Etc all right once you get that installed everything installed in your computer you need to reboot so again if you are on Windows you need the rest up the C++ Visual Studio code if you're on Linux or Mac go ahead and just grab this curl command run that then go ahead and download visual studio code all right reboot after that and then come back and meet me here because we have a little bit to do with inv Visual Studio code okay so when you get to visual studio code it may look a little bit different than what you're seeing on my screen that's okay what you want to do is find this extensions button over here on the left all right and you want to search for rust analyzer I've already got it installed on my machine but just search for rust analyzer you'll come over here and you'll just hit the install button for it all right that will give you rust analyzer that's going to allow you to analyze your rust code in real time and identify bugs and flaws as you go which is really really awesome and you're going to see it throughout the entirety of the course so by now you should have rust installed you should be able to run Visual Studio code you should be able to in install rust analyzer have that installed and then you should be able to meet me in the next video where we talk about actually utilizing rust creating our first project and running through everything so let's go ahead and stop here and do a quick quick video on documentation then we'll meet in the next video after that and we'll talk through setting up rust for your first project so let's go ahead and meet in the next video now that we've installed rust I briefly wanted to show you the documentation that is out there for rust and there are two really really good resources both provided by rust itself so the first one is a book called the rust programming language this is free to use open source and you can come in here and look at various areas so like installing rust hello world all the way down to variables functions you scroll down it just gets uh more in depth as it goes all right so there's tons and tons of information here about rust and if you ever have a question you're ever unsure you can Google it you can use the Rust book it's absolutely awesome another example of this is rust by example so it has an introduction but it starts out with hello world and all this shows you the code and everything within it it explains it explains a lot of things in detail and it's broken down really well I think I actually might like this a little bit better than the rust program language book but both are fantastic resources I found myself when I first got started going through back and forth reading various areas to get a deeper understanding because maybe one resource is not the best same with a course right like this course you may say hey I want to learn more about X Y or Z go out and read the documentation go out and try to have a deeper understanding of what you're seeing especially if you're confused by anything so I just want to point out that they're out there I'm going to link these in the description below this video so that you have these resources available to you please utilize them as you need so that is it let's go ahead and get started with rust okay let's create our first project in Rust now you can do this in one of two ways you can use a terminal or command line or you can actually use Visual Studio code if you're running Visual Studio code you can just go to terminal and do new terminal and what we're going to do here is we're going to run what is called cargo so we can type in cargo and we could type in new and then we can give this a name we could just say my rust project and then we can hit enter now what is Cargo before we do anything else cargo is the rust package manager it's also a build system amongst other things so it is what we're going to use to create our projects if you ever familiar with Pip in python or npm it's very similar and does a lot of things for us so here we're going to use cargo to create our project we can also use cargo to build and compile our project and we'll see the different cargo features as we go so we just created a new project and now we need to open this so what we can do is we can go to file and then open folder and you can see it on my screen but it's going to open up a window for you to allow to select a folder all you got to do is select the folder called my Rus project or whatever you called it and hit open and that will bring you to this screen here where now you can see your project so within the project we have a few things here we have this main project here or this Source where we have the main. RS we also have a tomel file and a lock file you can see other things being generated currently uh this tomel file is very important so this toml file is what has all of our configuration information in it so you can see we have the name of our project this is what's here we have the version of our project we've got the addition of rust that we're running right now which is 2021 and any dependencies that are in here so we don't have any dependencies right now we'll talk about importing libraries later and adding dependencies so you don't have to worry about right now but this file is where we add any dependencies to our configuration this will eventually get added to this lock file you're not supposed to be editing this as it says do not edit this just stores all of your dependencies for you in this lock file so your Tomo file is very important your other important file here is going to be your main. RS and if we want to run this there's a couple ways we can run our first program before we get into what the program does or any of the other stuff we can hit run up here if we have installed the rust tool that we went through the rust analyzer here right or we can actually do it from the term Al as well so if you take a look we can see that it says hey hello world it printed that out that's great and we can just hit any key to close this out we can open a new terminal we can actually do this from cargo as well so we can type in is Cargo run and then that will run this and you could see it says hello world as well so I like to just run it from up here anytime I want to run just hit run and and runs the project for us very easy so that is it for this video let's go ahead and pause here and I'll meet you over in the next one okay so you had an opportunity to look at our program in the last video and all this program does currently is it just prints out hello world very standard for any program that you run any coding language typically your first thing you write is hello world what's nice about this project is it's already built in for us so what we have here and what we're going to start with is just breaking this down before we go any further we have a function here or what's called fun and a function is a piece of code that we're going to get into in just a little bit all right I like to think of them as mini programs we'll have a whole section on functions coming up this function is main main is our main function it's exactly what it is this is where our program begins essentially that's how I like to think of of main okay and within our function we have this macro here and if you see me hovering by the way that is just to show you that you can hover over some of these things like a function or this print line and your code will tell you or your IDE or Visual Studio code will tell you what this is depending on the program that you're using here you can see that this is a macro I like to think of a macro as just a builtin function it's also a program of itself so what we're doing here is we're running a macro called print line or print Ln exclamation and we know it's a macro because of the exclamation point here at the end and then all we're saying is here is a string so a string here where it says hello world and I just want you to print out that string okay easy enough we run it and it says hello world great now if you're familiar with programming languages such as python you could run a print command as well and we can just say print and do hello world again for example and in here you'll see that if we save this contrl s or go up to file save and run it it will run if we take it one more time let's take a look at what we're actually doing and just save this one more time and run it okay there is no break line in here there's no new line that's occurring what's nice about print line compared to just print and why print line is used mainly is because it automatically gives you that return character or that new line character it's automatically built into this macro this little function so I'm going to go ahead and delete this here but that's the main difference here so what are we doing in this program we're taking main our main function and we're telling it to do something so that do something is run a macro print line to print out hello world that's pretty much it save it run it one more time and there we are we're back to hello world let's briefly talk about comments here so we have our main program and we can add some comments to it and this is what's going to make us a better programmer so we can come in here and comments within rust are done with two forward slashes it turns green you can see that we are writing a comment and we can just say this is a comment now why are comments important why do we care here well what happens if you're a developer and you're writing this out and tomorrow unfortunately you get hit by a bus and nobody knows how to read your code because you didn't put any comments in there that would be an unfortunate event you should be very detailed and documented what what you're doing not just if you're working internally at an organization if you're going to go put code on GitHub it's very nice of you to be able to put comments in not just for yourself but for other people again that can come in and read your code and understand your logic and what you're thinking so you can put things in along the way now there are many different ways to comment this is an example here we can actually comment right on the same line I can come in here and just say this prints hello world if you wanted to so you could put whatever you want within this comment here another thing that we can do is actually make these comments multi-line now you could do it like this for example you can come in here and say this is a comment adding a second line you can even add a third line and continue on but there's an easier way to do this we can come in here and say something like a forward slash and then add an asteris here and then you see it automatically created a comment for us here it created the ending of this asteris so this is what a comment block looks like so in here we can put this is a comment and then you can have it extend multiple lines and it extends multiple lines automatically something like that and as long as it's within this forward slash asteris and then the asteris and the forward slash here again anything within here is a comment it's not going to be read by code you can prove that and actually save it and then just run this really quick you can see all that prints out is hollow world nothing else is red here just our main function function and these are just for ourselves and our sanity and for other people as well so make sure that you write comments as you go especially when you're studying it doesn't hurt to put notes in here for yourself as you build out your program so something to consider and we'll be using this along the way as well so that's it for this video go ahead and see you over in the next one okay so this is right where we left off I'm just going to clean this up a little little bit and I quickly want to demonstrate errors to you so what is nice about having our terminal here and when we run this we can actually see some of the errors that happen so let's say that we're familiar with a different coding language such as python as an example in Python we can come in here and we can print lines or use a print statement right and we can come in here and instead of putting quotes we can do quotes like for hello world but we could also do like hello world and you can see this is already throwing an air for us it's yelling at us and you can see it lighting up because we can't use single quotes for a string like we could in Python not in Rust at least so if we come in here and we save this and then we try to run this we're going to get an air what's nice about this is the air will automatically tell you where it's at here your compiler will fail and you can see the error code that's here and it's says Hey undetermined character literal we're trying to run a character here which is done in single quotes and it's seeing that but a character is only one item and we'll get into characters in a little bit but we can't run a whole string in place of a character so what's occurring here is an air it's expecting one thing we're giving it the other and it's telling us what it's expecting if we're ever confused we can actually run this rust C command explain and it will tell us we can copy and paste this into a terminal and it will tell us exactly what's going wrong here so for example if we come in and we just paste this back and hit enter it'll tell you hey a character literal wasn't ended with a quote and it shows you an example of an error what that looks like so here it starts but doesn't finish with that single quote and to fix this error add the missing quote okay well we did that so this isn't incredibly helpful but it should give you some indication you can actually look a little bit further cuz this is a character again the more we learn the more we'll figure out but we can only put one character in here such as that that makes it okay so let's go ahead and save here I just want to show you that there are air outputs in the terminal you should be using that to debug as well and that will make your life a lot better we're going to have a lot of people and I see it all the time where people come and they say my codee's broken and the first question I will ask ask you is did you read the output and this is true for a lot of languages not just rust so make sure you're reading the output make sure you're Googling what you're seeing if you're confused at all and your IDE is your friend here so make sure you're utilizing this and what it's telling you when you're actually coding out as well so that's it for this video we'll go ahead and see you over in the next one let's briefly talk about Primitives so Primitives can be a few different things we have what are known as scalar types so we just say scalar types in here and these notes are for you as well so we can have an integer or an INT we can have a float we can have Boolean expressions and we can have characters of the Char okay and first things first what we're going to talk about are integers so you could think of an integer as like the number one or 100 or a th those are all integers and these could be represented in a couple of different ways we have unsigned I can type and we have signed okay and the way that I like to think about this is unsigned means never negative where signed means can be negative and positive so there would be situations where you might want to use one or the other typically we use signed as as a default even in Russ if you don't declare which you'll see declarations here in a little bit if you don't declare it's going to automatically default to what is known as i32 we'll talk about that here in just a second but there are different types for unsigned and signed we have u8 u16 u32 u64 U1 128 and U size and just like that for the unsigned have the same thing for signs we have I8 i16 i32 I64 and i1 128 along with I size so what do these mean well if we break it down the U is unsigned quite obviously and the I is for assigned integer and we have these numbers afterwards 8 16 32 64 Etc well this is the number of bits so the higher in bits that you go up the more data that it can hold and we can take a look at that here in just a second but the standard again is this i32 and most system architectures nowadays are running on 64bit if you wanted to run 64-bit you could however i32 is actually faster even on 64-bit architecture so this defaults to i32 you have to keep in mind what size you want to run depending on the architecture that you're running if you're running a something with like a 16bit processor you're not going to want to run a u 128 or an i 128 for example and lastly we have this U size and this I size the way I like to think about this is this is the number of bytes that it's going to take to reference any location in memory if you're not familiar with C that's okay but what you need to know is say we have a 32-bit Target and we say okay well I want to know the U size the I size well on a 32-bit Target it's going to be 4 byte if we're on a 6 4bit Target it's going to be 8 bytes and so forth we'll make declarations as we go and we'll explain things as we go so don't be overwhelmed at this point but let's quickly take a look at these sizes that we have here and we're just going to pick a couple out so if we wanted to say something like print line and we wanted to come in here and declare something like let's just say Max size of a u32 we can come in here and do that and we can say something like brackets like this do a comma and then we can come in here and just do u32 Max like this all right and then what this is doing is we have a string here the string is just saying Max size of a u32 and we put these brackets here this is a placeholder the placeholder that we're holding for is this right here and we're saying hey u32 this is an unsigned integer type that's exactly what it's telling us and Max is saying I'm going to to take the max value that can be represented by this integer type cool easy enough let's save that and just run this really quick and you can see here is the max size of a u32 okay well what happens if we take that up to 64 for example let me just copy this and we'll paste this we'll just make it a u64 and we'll run it one more time you can see that this number is going to be significantly larger okay so look at the number and the difference between 32 bits and 64 bits we could do the same thing I'm just going to copy both lines and we can look at the eyes here so if we just replace the U with an i in both of these and just see if there's any differences here run this and you can see there are some differences here as well all right so keep that in mind the differences again between unsigned and signed inte we know unsign can never be negative while signed can be negative and positive now we'll take a look at the other scalar types we just covered ins and something to note really quick we're not going to touch on it right now but there are what is called literal integers so we can call them or integer literals in literals whatever you want to call it here and these are a kind of literal for a value that is directly represented in source code uh so for example we could have decimals right like if I could type decimals like we've seen like 1,000 uh we could have like binary code such as binary we could say like uh 11 one one 000000 something like that and so forth so uh we've got those we'll cover those as we go uh nothing to worry about right now but just know that integers can be decimals they can be binary hex octal we can even have a bite as well so I'm going to go ahead and delete this but I just wanted to cover that really briefly for now we just want to know that we have unsigned and signed integers and they can vary in size depending on the architecture that you're running and the default that you should know is i32 let's go ahead and stop here and we'll move on to the next thing which will be floats so I'll see you over in the next video okay let's go ahead and talk about floats I'm just continuing on right from the last video we come in here and we can just say floats now floats only have two types we've got F32 and f64 and if you said hey that's for bit architecture you would be absolutely correct okay and we call these bits of precision as well so F32 has 32 bits of precision where f64 has 64 bits of precision 64 bits is actually the default or f64 is the default just like i32 is your default here f64 is the default however it can be slower on less than 64-bit architecture so if you know you're developing something for 32-bit architecture perhaps F32 might still be the way to go all right so with that in mind we can do something similar here I guess we should Define what a float is before I just throw information at you uh okay so if an integer is something like a thousand a float is something like a 1000.1 okay it's this 0.1 that we're after here now as an example a great example of a float that is used in most programming is pi 3.14 I think that's great now you couldn't have something like let me just space over here you couldn't have something like 0.14 okay this is not considered a float you have to have on the left hand side of the decimal value at least some integer there so or at least a number there I should say uh we have a 0.14 that would become a float at this time okay so just know the subtle differences here but I'm going to delete that and all I want to show you for this floats video right now we're going to get into math we're going to get into looking at integers and strings and all kinds of other stuff later on we just got to Define everything first so I just want to show you the different points of precision here if we come in here and we just print these out which we can and all we're going to do is change this to an F this time so max size in F32 f64 and we're going to do the same thing here just save this and then print this or I should say run this so if we just run this okay and you can see the different bits of precision here uh F32 versus 64 bit here all right so we can go into later on the amount of precision and looking at the addition of two floats if we wanted to you could take something like I don't know like a three .14 and then whatever the digits are and then just add that together and see the differences with the placeholder F32 versus f64 there's way more Precision on the f64 again because we have more bits there but you can actually prove that by adding two floats together if you wanted to we can cover that later on so that's it for floats we're going to go ahead and move on to the next scaler type okay next up our are Boolean Expressions so we can just type in Boolean and the best way to think about these is true or false and this will come into handy later we're not going to really get into it too much we just need to know that something can be true and something can be false and that's a Boolean expression they are represented by bull b o o l and we have statements that will make their conditional statements later on if you've never taken a program in class before that's okay but if we have an if statement for example if something is true then do this or if false then do this and that's really what boolean's after if something returns true we might want to do something later on or if it returns false we may have different conditional arguments based on true or false so knowing Boolean is very important and later on we're going to get into what are called Truth tables so you might see something like different operators such as as and or or and then we might say something like if something is true or false then it might be true uh versus we just say versus where something has to be true and false then it's false that might not make any sense right now and that's okay but we'll get into truth tables and why this can be important as well so boolean's great for conditional statements it's great for truth tables and we'll get on with that later in the course I just wanted to introduce you to the idea of true or false which is pretty straightforward at this point so that is it you can go ahead and delete this comment we have one more scaler type to cover and then we'll get on to more fun stuff in the course okay the last scaler type is going to be a character and this is actually defined as as CH h r you can call that Char or care or however you want to call it uh and all we need to know is this is four bytes so we saw the print line statement before and I'm just going to type one out as example we don't have to actually write this but we saw print line and we said okay well I wanted to print something and remember we tried to do like uh a string like a bus something like that that doesn't work but if you wanted to have a character of an a as an example you could print a character out uh depending on what you're trying to do so like a for example could be a grade that could be a character but characters also can be like emojis they could be Unicode it could be a lot of things whatever you want to store within that four bytes it doesn't have to be a letter and it's not a string so take it out of your mind that what we're looking at here is a string a character is a four by character that's it and it can be many different things so I'm going to go ahead and delete this right now just know for now that characters are four bytes they're represented by this CH and that's it we're not going to really use these that much in this course but it's still important to Define these so that's what we're doing outside of that we're done with this video so go ahead and see you in the next one let's now talk about very variables and why do we call them variables well because variables vary and rust handles variables a little bit differently than other programming languages we'll talk about the differences here in a second but let's just do what we've been doing but store it in a variable so we're going to do hello world but let's just declare a variable and we're going to do that by saying let and then we can just call the variable whatever we want here we'll just call it hello and we'll say hello is equal to we could put quote here for string and then we'll just say hello world and you can see that some things autop populate we have this declaration here of this ersan Str don't worry about that right now we'll declare what these are later when we actually cover strings for now just know that there's some Auto population going on and now we need to call this so let's do a print line and we're going to say we're going to put quotes here we're going to put these brackets again this placeholder here for what we're going to be calling and we're going to be calling hello so all we need to do is that we can save this and then we can run this and it prints out hello world now something interesting about variables at least in Rust variables in Rust are immutable and we can make a note here variables are immutable okay in most programming languages they are mutable meaning that if we came in here and we we just said hello is now equal to hello again and we printed this out we would imagine that this works in fact it will not work and I'll take a look at why so if we do the same thing and we just print hello again probably should just copied and pasted it but we're too far into this now all right we saved this you can see we've got an air already here because it's saying cannot assign twice to immutable variable we try to run this it's going to give us an error it's going to say exactly what it just told us cannot assign twice to immutable variable so immutable means it cannot change and that's what we're seeing here we cannot have this variable here be hello world and then change to hello again unless we declare it as mutable and we can do that with mut so now we could say let the mutable variable of hello be hello world and later on we can declare it again and now it's hello again we save this and then we run it and you can see Hello World hello again and variables Don't Have To Be Strings either we just use strings because they're easy but what if we wanted to take a number this time so let's make a variable and let's just call it X and we'll set x equals to 5 and then we'll have y we'll just set y equal to six why not okay here what we can do is say if we wanted to do math in Rust and we're not going to get into math right this second but just as an example we can declare both of these here right uh and then we could say equals and then you can have something like x y and then x + y if we declare here one more and we save this this should work so let's take a look at this run it okay math and rest we got 5 6 equals 11 this probably should be like a plus sign or something right and then run that again so math and rest 5 + 6 is equal to 11 what are we doing here we're declaring X as a number an integer and we're declaring y as an integer and this is why learning the integers are important because you can see what happens here we autop populated that sign integer at i32 so that 32bit signed integer remember the defaults we talked about this is again faster even on a 64bit system so we declare our variables five and six we plug them in and we can actually do math as well we'll get into math operators and other operators later on in the course but just letting you know that there are multiple ways to do variables they don't just have to be strings they could be lots of things that get stored within the variable okay there's one other item to talk about and those are constants so let's do constants down here and constants start with C NST just like that okay and there's a few different rules about constants first of all they have to be what's called scream case so before we were doing like X and we could say something like value X something like that right well here we have to call them as scream case we might say a number like that scream case just means all caps so we can say constant number and then we can give the number I don't know 17 but we need some other things in here we actually have to declare this expression here or we have to declare The annotation type so you see how we have an annotation type here that was automatically triggered for us we need to actually put that in here for this as well so we've got our scream case and this is an integer that we are giving it so we're just going to give it an i32 and now this looks okay so we have to declare in Scream case we have to declare The annotation the type annotation here and then we also have to make sure that we have a constant expression so this is what looks good here I'm going to go ahead and save that and then we can actually just print out the constant let's just do a print line and just make it simple let's give quotes and just print out number just like that we save this run it okay and you can see it prints 17 now why why do we care about constants why aren't we just using let here well constant can be placed outside of your function so right now everything we've been doing up to this point has been within a function and we're in the function main we can actually take this constant just copy it and I'm just going to delete this delete a few lines go above main here and then paste this save it and if we run this what's going to happen it's still going to print 17 okay so we can place them outside of the function they are Global this is a global variable they are immutable okay just like the other variables they are immutable and when it comes to compiling constants are actually very fast so there are benefits to using them they're Global they're immutable and they're fast that's awesome so depending on when we need a constant we may have something that we want to set specifically like a number or a value and we put that in here and we're going to keep that Global awesome so at this point we've covered the three different types of variables we have just standard old immutable variables with the let we have mutable variables which use the mut correct and then we have constants as well so make sure you understand the differences make sure you understand the rules of a constant that we have to use the scream case we have to define or declare the type annotation here and that uh we are able to use them in a global fashion as opposed to our other variables that we have so that's it for variables we're going to go ahead and jump into scope and Shadow so I'll see you over in the next videos let's talk about scope and shadowing so we have a function main here let's declare a variable of X again and we'll just declare this equals to one and within blocks of code we have our scope so this x is within this block of code here we've got our curly braces that's a block of code in theory we could have another block of code we'll see this with if statements conditional statements other things but we can have other variables declared within here we can have like let y equals 2 now within this block of code we can actually come in here and just print line and call out both X and Y if we wanted to we could just say something like again we could do math why don't we just do math we'll say math and we'll just do x + y equals okay and then we'll just do this here and we can say x + y equals we'll give a comma and we'll just do X+ Y and the output should be three and if we save this run it okay math X+ yal 3 now what happens if we take this print line statement and we just come outside of this block of code we paste this and we run this what happens here well I saved it and now I have an erir what's going on well well we have a local variable okay well what's happening is this Y is living inside of this block of code because this Y is inside this block of code it's only going to run within this block of code this is not a global variable it's local so our scope is important here where you can see we have a local variable to this function of X and that runs fine now if we took the Y for example and we just moved it up that would fix this code here and in theory just do something like this save it and then that would be fine and now you can see it prints the statement twice which is what we're expecting so understand scope scope within a block of code is all that happens remember we have constants if we want variables to live outside of our functions but we can also declare variables within a function or within a block of code and where those variables live matter so if you only want to use a variable for one instance or one statement you can do that and then once it gets out of the block of code you'll never see it again and that's awesome too so you just have to understand when and why you're going to use variables in certain situations and where their scope is local to or Global to okay let's talk about shadowing as well so let's delete this y here and we're just going to actually make a print statement of X let's just print out X okay so I'm just deleting some things all I want to do is print out X here I'll delete this as well so if x is equal to 1 and then we declare X here set that to two and we copy this print statement and we put it down here something like that what do we think's going to happen we've got the variable of X being one and then we say no no X is 2 and then we're going to print out X and then we're going to come back here and we're going to print X again all right
Original Description
Thank you so much to Snyk for sponsoring this video. Sign up for Snyk for free to secure your products from the start: https://snyk.co/thecybermentor
Want more Rust? Check out the full Rust 101 course here: https://www.tcm.rocks/rust-y
Sponsor a Video: https://www.tcm.rocks/Sponsors
Pentests & Security Consulting: https://tcm-sec.com
Get Trained: https://academy.tcm-sec.com
Get Certified: https://certifications.tcm-sec.com
Merch: https://merch.tcm-sec.com
Discord: https://discord.gg/tcm
📱Social Media📱
___________________________________________
Twitter: https://twitter.com/thecybermentor
Twitch: https://www.twitch.tv/thecybermentor
Instagram: https://instagram.com/thecybermentor
LinkedIn: https://www.linkedin.com/in/heathadams
TikTok: https://tiktok.com/@thecybermentor
Discord: https://discord.gg/tcm
💸Donate💸
___________________________________________
Like the channel? Please consider supporting me on Patreon:
https://www.patreon.com/thecybermentor
Support the stream (one-time): https://streamlabs.com/thecybermentor
Hacker Books:
Penetration Testing: A Hands-On Introduction to Hacking: https://amzn.to/31GN7iX
The Hacker Playbook 3: https://amzn.to/34XkIY2
Hacking: The Art of Exploitation: https://amzn.to/2VchDyL
The Web Application Hacker's Handbook: https://amzn.to/30Fj21S
Real-World Bug Hunting: A Field Guide to Web Hacking: https://amzn.to/2V9srOe
Social Engineering: The Science of Human Hacking: https://amzn.to/31HAmVx
Linux Basics for Hackers: https://amzn.to/34WvcXP
Python Crash Course, 2nd Edition: https://amzn.to/30gINu0
Violent Python: https://amzn.to/2QoGoJn
Black Hat Python: https://amzn.to/2V9GpQk
My Build:
lg 32gk850g-b 32" Gaming Monitor:https://amzn.to/30C0qzV
darkFlash Phantom Black ATX Mid-Tower Case: https://amzn.to/30d1UW1
EVGA 2080TI: https://amzn.to/30d2lj7
MSI Z390 MotherBoard: https://amzn.to/30eu5TL
Intel 9700K: https://amzn.to/2M7hM2p
G.SKILL 32GB DDR4 RAM: https://amzn.to/2M638Zb
Razer Nommo Chroma Speakers: https://amzn.to/30bW
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from The Cyber Mentor · The Cyber Mentor · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Buffer Overflows Made Easy - Part 1: Introduction
The Cyber Mentor
Buffer Overflows Made Easy - Part 2: Spiking
The Cyber Mentor
Buffer Overflows Made Easy - Part 3: Fuzzing
The Cyber Mentor
Buffer Overflows Made Easy - Part 4: Finding the Offset
The Cyber Mentor
Buffer Overflows Made Easy - Part 5: Overwriting the EIP
The Cyber Mentor
Buffer Overflows Made Easy - Part 6: Finding Bad Characters
The Cyber Mentor
Buffer Overflows Made Easy - Part 7: Finding the Right Module
The Cyber Mentor
Buffer Overflows Made Easy - Part 8: Generating Shellcode and Gaining Shells
The Cyber Mentor
HackTheBox - Sunday Walkthrough (Re-Up)
The Cyber Mentor
Networking for Ethical Hackers - TCP, UDP, and the Three-Way Handshake (Re-Up)
The Cyber Mentor
Networking for Ethical Hackers - Network Subnetting (Re-Up)
The Cyber Mentor
Networking for Ethical Hackers - Network Subnetting Part 2: The Challenge (Re-Up)
The Cyber Mentor
Networking for Ethical Hackers - Building A Basic Network with Cisco Packet Tracer (Re-Up)
The Cyber Mentor
HackTheBox - Fighter Walkthrough (Re-Up)
The Cyber Mentor
Beginner Linux for Ethical Hackers - Navigating the File System
The Cyber Mentor
Beginner Linux for Ethical Hackers - Users and Privileges
The Cyber Mentor
Beginner Linux for Ethical Hackers - Common Network Commands
The Cyber Mentor
Beginner Linux for Ethical Hackers - Viewing, Creating, and Editing Files
The Cyber Mentor
Beginner Linux for Ethical Hackers - Controlling Kali Services
The Cyber Mentor
Beginner Linux for Ethical Hackers - Scripting with Bash
The Cyber Mentor
Beginner Linux for Ethical Hackers - Installing and Updating Tools
The Cyber Mentor
Cracking Linux Password Hashes with Hashcat
The Cyber Mentor
Reminder: Twitch Hacking Live Stream Tonight! 2/26/19 at 8PM EST
The Cyber Mentor
Hacking Live Stream: Episode 1 - Kioptrix Level 1, HackTheBox Jerry, and Career Q&A / AMA
The Cyber Mentor
Hacking Live Stream: Episode 2 - HackTheBox Active, Vulnserver Buffer Overflow, and Career Q&A / AMA
The Cyber Mentor
Hacking Live Stream: Episode 3 - Hack The Box Blue, Devel, and Career Q&A / AMA
The Cyber Mentor
New Zero to Hero Pentest Course, New Website, and 2K Subs?!
The Cyber Mentor
Zero to Hero Pentesting: Episode 1 - Course Introduction, Notekeeping, Introductory Linux, and AMA
The Cyber Mentor
Zero to Hero Pentesting: Episode 2 - Python 101
The Cyber Mentor
Zero to Hero Pentesting: Episode 3 - Python 102, Building a Terrible Port Scanner, and a Giveaway
The Cyber Mentor
Zero to Hero Pentesting: Episode 4 - Five Phases of Hacking + Passive OSINT
The Cyber Mentor
Zero to Hero Pentesting: Episode 5 - Scanning Tools (Nmap, Nessus, BurpSuite, etc.) & Tactics
The Cyber Mentor
Zero to Hero Pentesting: Episode 6 - Enumeration (Kioptrix & Hack The Box)
The Cyber Mentor
Zero to Hero Pentesting: Episode 7 - Exploitation, Shells, and Some Credential Stuffing
The Cyber Mentor
Installing Windows Server 2016 on VMWare in 5 Minutes
The Cyber Mentor
Zero to Hero: Week 8 - Building an AD Lab, LLMNR Poisoning, and NTLMv2 Cracking with Hashcat
The Cyber Mentor
A Day in the Life of an Ethical Hacker / Penetration Tester
The Cyber Mentor
Active Directory Exploitation - LLMNR/NBT-NS Poisoning
The Cyber Mentor
Zero to Hero: Week 9 - NTLM Relay, Token Impersonation, Pass the Hash, PsExec, and more
The Cyber Mentor
Zero to Hero: Episode 10 - MS17-010/EternalBlue, GPP/cPasswords, and Kerberoasting
The Cyber Mentor
Writing a Pentest Report
The Cyber Mentor
Zero to Hero: Week 11 - File Transfers, Pivoting, and Reporting Writing
The Cyber Mentor
The Complete Linux for Ethical Hackers Course for 2019
The Cyber Mentor
Full Ethical Hacking Course - Beginner Network Penetration Testing (2019)
The Cyber Mentor
Popping a Shell with SMB Relay and Empire
The Cyber Mentor
Pentesting for n00bs: Episode 1 - Legacy (hackthebox)
The Cyber Mentor
Pentesting for n00bs: Episode 2 - Lame
The Cyber Mentor
Pentesting for n00bs: Episode 3 - Blue
The Cyber Mentor
Web App Testing: Episode 1 - Enumeration
The Cyber Mentor
Pentesting for n00bs: Episode 4 - Devel
The Cyber Mentor
Pentesting for n00bs: Episode 5 - Jerry
The Cyber Mentor
Web App Testing: Episode 2 - Enumeration, XSS, and UI Bypassing
The Cyber Mentor
Pentesting for n00bs: Episode 6 - Nibbles
The Cyber Mentor
Web App Testing: Episode 3 - XSS, SQL Injection, and Broken Access Control
The Cyber Mentor
How NOT to Approach a Cybersecurity Mentor
The Cyber Mentor
Web App Testing: Episode 4 - XXE, Input Validation, Broken Access Control, and More XSS
The Cyber Mentor
Pentesting for n00bs: Episode 7 - Optimum (hackthebox)
The Cyber Mentor
Pentesting for n00bs: Episode 8 - Bashed (hackthebox)
The Cyber Mentor
Pentesting for n00bs: Episode 9 - Grandpa
The Cyber Mentor
Top 5 Internal Pentesting Methods
The Cyber Mentor
Related AI Lessons
⚡
⚡
⚡
⚡
Claude Code Is Steganographically Marking Requests
Dev.to AI
SimpleHelp Flaw Exploited to Deploy Malware Targeting Windows, macOS, and Linux
TechRepublic
iPhone Security Fixes May Arrive Sooner as AI Speeds Up Threats
TechRepublic
Apple rushed to squash 29 bugs because AI is supercharging hackers - update ASAP
ZDNet
🎓
Tutor Explanation
DeepCamp AI