HirschDaniel cuts through the noise with a terminal-first approach that prioritizes raw logic over superficial IDE abstractions. It is a refreshingly pragmatic guide for those who prefer building systems to watching slides.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Rust from Scratch (Beginner)Added:
Guys, it's time. Finally, the time has come.
And I've received this request at least a hundred times. No joke. Um that I should look into Rust and make a Rust project.
I have no idea of Rust, however. So, I can't just uh log into my terminal and start coding something like I do with C.
So instead of just trying to code something um today I want to start exploring Rust. I know it's a compiled language. I know it's super hyped right now. I know it's trending. I know it will go away probably. No, but I don't know. No, but there have so there have been so many hyped languages in the past. Maybe Rust is one of them. Maybe it's not. I don't know. I have no idea of Rust. I remember a couple of months ago I tried to subject to your request and try to learn about Rust so that I can record more Rust or that I can record Rust content in the first place on this channel. But um somehow something just didn't feel right. So what we're going to do today is I want to try to create a small project in Rust. Don't judge me. I have no idea.
I'm a complete Rust noob. Okay, so I I don't know yet what the project is going to be. I know Hello World is a possibility, but it's incredibly boring.
The famous numbers guessing game is also a possibility. It's probably too boring as well. I'm not sure what I'm going to do. Let's just see. I want to just explore the Rust ecosystem. So, let's just search for Rust on Google. And for those of you who don't know what we're talking about is it is this Rust programming language that we're going to explore today. Rust is a general purpose programming language basically like every programming language. I don't know any single programming language that is not general purpose except maybe uh maybe some dedicated automation programming languages for specific machines or something like that. But all the programming languages that you already know like Java, C, PHP, JavaScript, [sighs and gasps] whatever else there is are general purpose programming languages. So I never understand why it's mentioned here. And Rust emphasizes performance, type safety, concurrency, and memory safety. Rust supports multiple programming paradigms. It was influenced by ideas from functional programming including immutability, high order functions, algebraic algebraic data types and pattern matching.
Okay, so it's super generic. What I personally know about Rust is that it's a language that is used for creating low-level applications in a typesafe way. You probably know all the possible bugs that you can do in pure C.
So whenever you write programs in C, it's incredibly simple to introduce bugs. It's still possible to in to include or to create bugs in Rust.
However, some specific bugs are impossible are made impossible via Rust's compiler. I think maybe we can find something out about that on the Rust language website here.
And I know that some Linux applications are trying to migrate toward Rust.
However, there are I mean it's it's not only a good move here that that we migrate legacy applications like um built-in GNU core utilities like uh catless and all these command line applications that we migrate them all to rust. It's not necessarily good because those have been battle hardened for 30 if not 40 maybe even 50 years 50 years I don't know but it's that it's that order of magnitude in years so we have such battle tested software written in C it's been around for decades and now people are trying to rewrite that stuff in Rust I don't know if it really improves anything because that software is almost guaranteed to be bug-free and rewriting stuff in Rust comes with the risk of introducing new bugs and also of course bloating the size because Rust applications are not always as small as C ones as far as I know but that's usually because this the libraries are statically bound by default.
[snorts] I think that's about it. That's about what I know about Rust. Then I know something about the that there's some kind of dependency management tool. Yeah, Rust up. I think I still have it installed from my last experiment. Let's check.
Oh, no. I don't even have it anymore.
[snorts] Okay. Probably because that's because I messed up my operating system and had to reinstall from scratch a couple of weeks ago, probably. So, Rust got lost, but I didn't really miss it in the meantime.
So, let's create a project directory and call it the Rust Exploration here.
And then CD into it. And I create a source file. I don't know what it's going to do. Um, let's call it app. No, no. App sounds like some front end thing. Let's call it I don't know. I don't know what it's going to do. Let's call it rust.rs.
I think rs is the extension for rust.
And now from the top of my mind, I don't know anything anymore. Um, there's no such thing as include, right? There's no ah god. Okay, now I need to now I need the documentation, guys.
So, where do we start? I know there's a a tutorial about Rust somewhere. Here's an introduction. Let's maybe make it a bit bigger for you guys such that you can follow along. [sighs] And yeah, this is the primary reference for the Rust programming language. We don't need the reference. We actually need a tutorial.
I know. Um right. Cargo. Cargo is the Rust package manager and build system.
So Rust is used with this package manager. We'll see it in a few minutes, I think. So how do I learn Rust? Now there's some book the Rust programming language.
Right. I I remember this one. So this for [snorts] those of you who don't know Rust and who want to learn it, that's probably the best resource to get started. You it tells you what to install. You need to install Rust app.
So you probably can just copy this super nonsuspicious uh stuff here and pipe it into shell. That's always a great way to install it. Nothing can go wrong here.
Impossible.
Uh so no. Okay, let's let's properly do it. Let's be uh let's not um be stupid because I've been stupid um too many times. Here, this right here is the installation command because we are safe engineers and we don't fool ourselves.
Let's copy this link and see what's under there because we're just piping it into shell which is incredibly risky in real life. So, what's to be found here?
A shell script. If I open it here, um, ah, I can probably also just do wget and then paste the link here. Download it.
Uh, and I should have downloaded it.
Downloaded it into the Rust exploration.
That would be nicer. So, let's do it here. Wget [gasps] rust. RS that sends an HTTP request to that website here and downloads index html.
Wait, but index html is an HTML website.
Ah, no, but it Okay, the index html is the script. That's interesting. So, this is now a script. This is just a little script that can be downloaded from the internet to install Rust up.
Let me just fix up the formatting so you can follow along here and see. And this is doing some stuff. Okay. Okay. It's all validated by me now. Now it looks like some regular script so far using get opt to parse the options here and I have no idea what it's doing aside from that.
Okay. But now we have validated the installation script. That's how it works. Perfect. Now we I can guarantee nothing dangerous is happening here. So, let's um install let's install Rust here.
Ah, damn it.
Where's the link? Or the installation command here. There it is. Let's go. And command is not found because I copied the dollar sign. Now, it should work.
I proceed with the standard installation. So I hit enter and some stuff is being downloaded.
[snorts] And how much is being downloaded here?
So we're already in the in the order of magnitude of hundreds of megabyte.
Is that already more than C? No idea. So this is installing cargo which is the package manager the dependency management system used in Rust. Clippy I have no idea what clippy is. Rust docs should be obvious. It's documentation for Rust. What else was installed?
Rust standard is probably the Rust standard library. Rust C is the Rust compiler and Rust FMT sounds like some file mount or format. H Rust format.
Maybe it's a maybe it's a source code formatter, but I'm just guessing at that point.
And now to get started, you may need to restart your current shell. Okay, this would reload your path environment to include cargo spin directory.
To configure your current shell, you need to source the corresponding end file. Okay, because I know whenever such things happen, I mess up everything and I don't source all the shells, etc. I just terminate all the shells that I have on my screen right now and restart my entire terminal. So, let's go here. I have a shortcut, by the way, for instantiating my terminal, which is incredibly useful. Um, it should just adapt the splitting of the T-max tabs here.
And now we have this Rust exploration directory with the installation script downloaded as an index html. I'm going to remove that. And now I should have rust C installed. Let's just let's just check here. Rust C.
Okay, so this is a compiler. It's waiting for input and therefore it's not printing anything. But if I enter a line here or Ctrl D, Ctrl + C, I don't know. I I have no idea how Rust C is implemented.
So I can't really judge how it's passing how it's processing input, but it's installed. Okay. What about cargo?
Should be installed as well. Those two are the important things. Yes, Cargo is also installed. Now, what do we do with that? Cargo's Rust package manager. Do we need to use cargo to create to create a Rust project? Because that's the case in many programming languages. for example, well, it's not necessary, but it's a common practice because a couple of episodes ago, a couple of episodes ago where I explored React there, it was necessary or a common practice to use npm to initialize the project directory.
Is the same the case in Rust?
because there's an init there's an init command here and a new command create a new cargo package I don't know if we are even creating a cargo package is a cargo package an application that we are creating ourselves I think so but do we need a cargo package or is a cargo package only used to distribute our software were to other people.
H I could now of course just fire a command and see what happens. But in the past, this has proven that it tends to [laughter] it tends to destroy my my Linux installation. So, I'm not going to do it this time. I remember so many times where I just completely trashed my system uh while you were while you guys were witnessing. I don't want to do it yet another time because when I I mean invoking a command here is just it's a subsecond thing, right? But then uh reinstalling the entire system and trying to trying to uh recover everything is u many hours if not days worth of effort.
So we have now all the stuff installed.
What do we do from where do we go from here? There's a hello world tutorial.
Okay, let's go through the hello world tutorial. So we create a project directory. I'm not going to read through all of this. Um we have we already have created a file that is called what?
What's our file called? Nothing. Didn't I create a file? Okay, then let's create a hello. RS. Probably I didn't save the file. And let's create a function. What happens if I type FN and tap? Ah, of course. So, my Vim plugin that the Vim plugin that I'm using has autocomp completion and it knows a couple of Rust syntax.
Um, a bit of Rust syntax. So, we create a main method. Oh, what's that?
Ah, okay. I I type fn then autocomplete [clears throat] which creates a rust function but then I type main which creates yet another rust function. So probably a rust main method is main and then tab in my case. [gasps] Yeah, looks like that. That's probably a public function main which is equivalent to this right here. The public can be omitted of course. This was just coming from my autocomp completion plugin.
So nothing rust specific.
Then what's the next step?
By the way, one thing that stood out to me is when we do a print line in Rust, we don't just do print line and then pass the argument here. We do print line exclamation mark and then hello world. I don't know why that is. I don't even know. Do we need a new line? No, we probably don't need a new line because the function itself is a print line function. So, it will append a new line. Do we need semicolons in Rust? Yes.
Um, I think I read somewhere that rust function with exclamation marks, they are macros or something like that. Some those are special functions in in Rust.
this with exclamation mark. I can't I cannot imagine that every function has an exclamation mark after its name. That would be unnecessary. So, it must have a reason and the reason must be good. And let's try to find out the reason for that.
Um I don't know why my internet connection is now not loading. Let's just disconnect from the VPN. Of course, now it's loading within [laughter] no time. Okay. So come on. So Rust is a curly brace language with semicolons, C++ style comments and a main function. So far so similar. The exclamation mark indicates that this is a macro call. Okay. Right.
So what is the diff? What is Rust macro?
What is a Rust macro? Maybe I need to disconnect from the VPN just for this episode here.
Somehow something is slow today.
Macros are a way of writing code that writes other code. It's okay. It's similar to C. Maybe maybe it's similar to C where a macro is a simple string substitution.
And in Rust macros allow meta programming. Okay, so it's the same thing as in C probably. So this is a macro named say hello here.
It's initial initialized like this and it replaces all occurrences of say hello exclamation mark like this with this anonymous function call.
That's how I would understand it.
Okay. So we probably don't dive into the intrinsic complexities of Rust macros today, but it's nice to understand that this is just a macro. It's not a regular function. So um that's where the exclamation mark comes from. But I don't know what where where does the necessity for a macro for a simple print line function come from come from? Maybe and this is just a guess. Put it in the comments if you know. Maybe print line is a macro because if it was not not a macro it would need to be imported from somewhere. So this is maybe a way to execute code without importing it from somewhere. Maybe this macro is I don't know it's injected somehow into the compiler.
[laughter] No idea guys.
And okay so we have talked we have talked so much about a single function.
Now let's try and see what happens if I just rust C this file as if it was a regular C file where we usually compile programs doing CC and then the name of the source file and then that's it.
Let's see what happens in okay. Of course nothing happens here. So it works differently. Oh, but it shouldn't. It should work just the same. So, we save the file, go back to the terminal, and enter the following command to compile and run the file. And we do this. And then we should get a hello hello world.
Maybe I didn't save the file. So now, why doesn't it do anything? Oh no. Oh no.
[snorts] So, ah, Daniel records the great rust exploration. Such a nice video. I'm looking forward to it. Save it for later. Okay. Later, two hours later, the viewer joins the video, opens the video, watches 20 minutes of it, and just to watch Daniel fail compile a freaking hello world in Rust. So, what's wrong here?
Function main print line.
Why doesn't this do anything? No, guys, seriously, this is ridiculous. Didn't I Did I miss anything?
Hello RS.
LS late. There's the file. It's hello.
RS. Rust C help. Why is Rust C just wait which Rust C?
Okay.
And this looks okay.
What if I do what if I just do this?
[sighs] Something is wrong with my Rust scene, guys. This is always Well, I don't I don't get it. I want to explore technology and programming languages and and learns learn things, but I can't learn things if if [laughter] these simplicities are always failing.
Oh, come on. So, Rusty not doing anything.
What am I supposed to search for?
[sighs] Rusty does not run simple hello world program. Rusty is the compiler. Yeah, that's clear. Of course, I understand that it's the compiler.
[sighs] Do I need to restart my entire machine?
Probably not.
Rust Cats.
How about reinstall Rust C?
Uninstall and reinstall Rust C.
Oh no, now comes the dangerous face where I just copied something from online. Rust up default stable. How about that? Because rust up is the Rust updator. I saw that in a sentence um earlier somewhere here. Rust up, right?
Um the first step is to install Rust.
Wait, we we download we'll download Rust through Rust app.
What did I do? I installed some script that I just copied from somewhere.
Ah, that was the Rust app installer. So, I installed Rust up, but then what did it I I thought rust up installed uh [sighs] Rust C.
What happens if I run this command? Rust up default stable.
Nothing happens.
Stable timeout regarding no time out reading Rust C version.
Why? That's ridiculous guys.
I've installed Rust C via the online install file. Currently running rust up shows rust up show on iron shell shows this.
This means that the command rust up runs to get the rust C version hung without any point. You should you could start to track down blah blah blah. This is still an issue. In fact any command involving rust c hangs.
How? I think this is done on intention by the universe to me. They just want to throw stupid issues into my way.
Indeed, there's a 3 second time out blah blah. Okay, I'm just going to restart my machine and then see if it's resolved magically. Let's go. So, I am back.
Let's restart everything here. Terminal is set up.
Uh, just need to format this a bit. And now we're good to go. CD cd into the Rust exploration directory. And now comes the big moment. Rust C. Hello. RS.
[sighs] Okay, so I'm [clears throat] okay. I'm going to figure this out, guys. This is This is incredible.
>> [snorts] >> Rust C reinstall Rust. How about that?
Ubuntu.
Mhm.
Using Rust up, we do this. Okay.
Rust up self uninstall. How about that?
Yes.
Oh, that was fast. The uninstallation was very fast.
And now I reinstall it.
What happens now?
Let's see if it works.
[snorts] In the meantime, what is the next thing that we can do? I mean, okay, now we have a hello world.
It does not work yet. That's fine.
I'm just going to switch it over to here and the installer here. I don't know why it's not doing anything.
What if I disconnect from the VPN? Does that change anything?
I I think um somehow Rust just wants to play with me. Guys, I know that was your intention. You wrote it in the comments just to prank me and you probably replace the scripts, the installation scripts and all that stuff just to play with me. [gasps] Rust uninstall passing d- uninstall.
I have incredible internet speed today.
Oh, now something happens. Okay, I proceed with the standard installation.
Yes.
Oh, [clears throat] then the next thing to do is hello. RS.
There's our hello world. I'm not I don't even know what to do here. I mean, it's just a hello world. It's just supposed to install successfully.
Do you also install Do you also see the screen flickering here? Because the installation screens, the installation script seems to cause screen flickering for me. Don't know if it's visible in the recording.
Probably it's due to due to how the terminal is being updated here.
Rust Docs. Wait, so cargo is installed.
Clippy is installed. Rust Docs is installing. Rust stand. Why is it so slow? Come on.
Let me just pull out my Wi-Fi connector and plug it back in. Let's see if that changes anything.
Was that a maybe a stupid idea to just remove the Wi-Fi connector right now [sighs] speed test run speed test?
Mhm. Okay, it's fineish.
Not super good, but also not super bad.
Now the installation proceeds. That's good.
So Rust C is apparently installed now.
Rust Docs is still downloading. Okay, we don't need Rust Docs, but still it's supposed to work. Okay, Rust is installed.
To configure your current shell, how many do I have? I have three right now.
>> [sighs] >> Um, you need to source the corresponding end file under home cargo.
Okay, let's do it. I use these kinds of shells here.
So, can I just do this?
Okay. And then rust C. I don't get it, guys. I really don't get it. Why is it not doing anything?
uh Rust C version. It doesn't even do anything.
And what if I install Rust C here?
I'm just going to install Rust C from somewhere else. I don't care. Sudo up install Rust C.
Okay.
>> [snorts] >> And in the meantime, let's open the guide again.
Oh, it's already installed. I thought it was printing at 300 megabytes are required. So, that was kind of fast for 300 megabytes here.
[snorts] But maybe it was downloaded somehow compressed and then extracted.
What if I do rust C now?
Rust C version.
Which Rust C? I don't get it guys.
Why am I always suffering in my in my videos? I mean YouTube is not supposed to for suffering. Is it?
So rust C rust C version Rust C does not do anything.
Ra times out.
I think I know why. I know why, guys. I had a timeout problem in the past as well.
And it had something to do with the fact that I manipulate the time in my in my in my terminal. Wait, if I just launch a terminal without my shortcut, but vanilla from the from the systems applications uh widget. Let's see if it happens here. I'm just going to cd into projects rust rust exploration. Then in here, t-max do all of this. So my shortcut was intended to do all these actions automatically. And if I do rust cy now, of course it works. Oh god.
Okay. So what's going on? What has been going on is this is ridiculous. I'm sorry guys. Sorry for wasting your time.
I have a shortcut that launches a terminal. However, that shortcut also modifies the time in the terminal using some kind of time modification command.
And if an application is timesensitive, then it might be somehow impacted by the system time that is changed. Why do I do that? Because if when I create a video, [snorts] I don't want everybody to um be able to follow exactly the time at which I create the video because I want it to be timeless and I don't want people to uh just know at which times I record videos obviously. Um so therefore I just default the time to midnight always. for rust C it does not seem to work and I have to use the real time at which I record so the terminal needs to match this the terminal time needs to match the system time I don't know why it's necessary for us see but that seems to be the case interesting uh it's an interesting finding by the way so why could a compiler be timesensitive. A compiler is a completely deterministic um thing that just acts on its inputs as far as I know. So how is it how is a compiler's behavior modified by system time?
[snorts] That's a good question and I have no idea what the answer could be.
Anyways, okay. Now, now we are set after over half an hour of recording here. I have finally managed to create a hello world. RS file and probably I can just rust see hello. RS it. Now there's a hello world binary. It's only 4.2 mgabytes.
>> [laughter] >> So, it's quite big. But I had an argument about this in the comments in one of the previous videos where someone asked about Rust and I responded that I can't even code C properly. So, I won't look into Rust anytime soon. But now here I am. And also I I argued that [gasps] uh hello world binaries over 4 megabytes are ridiculously large. However, the well, one of you guys responded that that's because the entire Rust standard library is statically linked inside this executable. And that's the reason why this is so big. It's of course possible to have a dynamically linked executable.
But then Rust, the Rust standard library must be installed on the system. So now this hello world is system independent.
Of course, it must match the the processor architecture. But aside from that, it runs on any system that matches the architecture. But if you have a dynamically linked library, then of course the standard library, the Rust standard library must be available as far as I understood. So let's execute this. And we have a working hello world after only half an hour. Okay, what else can we do? So hello rs. Let's go in here and see. I have no idea about anything in Rust. So, let's go back to the Rust learning page and then read the book. That's the website we were on. Programming a guessing game.
Let's have a look at some syntax. So, um wait, set up a new project. To set up a new project, go to the projects directory that you created in chapter one and make a new project using cargo.
Why is that even necessary? Probably because we need we need dependencies.
Okay, let's create a let's just follow this. I'm going to create a new a new project using cargo new after fixing up my terminal that I just messed up again.
So, let's do this.
Oh god. Cargo new and then give this a name.
Go to the projects directory. Ah, okay.
Wait, I'm just going to create a subdirectory here. So, cargo new and let's call it the random um project because the guessing game is guaranteed relying on random numbers. Let's go down here. Generating a random number. There it is. Generating a secret number.
And that relies on a rand function. A rand crate is probably some kind of module that Rust can plug in and then we need to somehow add it to the dependencies.
Okay, so I'm going to create a new random project here. Creating binary random package. Let's list the contents here. Okay, there's a subdirectory called random now.
And if we list the contents then we have this cargo toml file. What does it contain? It contains some package information similar to Java's Maven or I think also Gradel or these um Python package managers like UV.
Um so you give your own project a name, a version and this additional thing and then you list also dependencies that you have. We have a new dependency later that is this random number generator here.
Okay. And my first impression of this code is is is um is it fair to say already I find this hard to read but that's probably because I'm not used to it.
So we create a variable secret number from it's coming from the random create package. I don't know. And then there's this thread random number generator. And we generate a number within a range.
What's that syntax? Why is it not accepting just one, 100?
Gen range.
Okay. So what about we just create a small program to generate a to generate a random number. And I'm going to type it out manually. So I am going to add this cargo thingy.
This car this random crate is it called crate even rust crate. What's a rust crate? A crate is the smallest amount of code that the Rust compiler considers at a time.
What's a crate in Rust?
[sighs] The crate part essentially means root of current crate. So crate means everything at the top level of the crate and thus we use create. Use crate brings all top level symbols of a crate. So it's basically a package, isn't it? A crate is a compilation unit in Rust.
Okay, then let's do rent equals 0.8.5 just like in the tutorial and then do cargo update just like the tutorial told us to. Now we have write cargo prints that it updates the index. It locks packages to something and then adds the crate that we have just added here.
It has added rand version 086.
I remember that there was some versioning semantic here. The specifier 085 is actually shortand for this.
So this circle small roof icon 8 085 which means any version that is at least 085 but below 09.
Aha.
So that's why we got 086 as a version.
We don't use the latest version. Why don't we use the latest version?
Probably because this tutorial here is tailored to the specific version, right? Any version 090 or greater is not guaranteed to have the same API as what the following example uses. So the tutorial used a specific version and then when we have this minor version upgrades. So after the zero which is the major version we have this minor version. I think it's called like that.
And then if there's an increment of this second part of the version then we have then we likely have a an API change. And since this tutorial was written for a specific API in this create, we cannot use it one to one.
And then what do we do? We just let's just have a look at the code.
So this is how we create variables and this is how we print them. This is already very good. So let's create variables and print them. That's good.
That's something that I probably should start with.
I'm tending to jump from one place to another. So in the main method, what do we do?
Let's move the main method here and go here. Let x equ= 5. Then paste x here. I think that's how I remembered how worked. If we cd into the random subdirectory here, which is our current projects directory and then I do cargo build, it probably compiles everything, right? It compiles lip C. So standard li C library apparently is is that the standard C library compiles get random rand core. So it downloads sources and compiles them.
And the last thing that was compiled after our custom >> [clears throat] >> uh dependency here is this random project which is our own project. And now we have a target directory. It's the same thing in Java Maven by the way which I'm very used to. And if in the target directory there's a debug directory. And in there there's a random binary file then we have succeeded. So this is our compiled program. We can execute it now. And we have a hello 5 world. Okay. And that's probably what we need the macro for in the print line because we can just pass in these curly braces the variable and it prints out successfully. If this was not a macro then for sure we would have to pass it somehow explicitly to the function. But this is what the macro is used for.
Okay. So there's already some learning effect here. That's nice.
Now what's the next thing to do?
Ah so we can pass x here and then we can also pass in empty curly braces and it will use the arguments the positional arguments after the string to and and put them inside the print line.
Let's try that.
Hello and then empty curly braces. What happens if I don't write a number there but a string Daniel? So the expected string is hello 5 and Daniel, world.
If I cargo build this this build okay nice and now let's execute. And we have hello 5 and Daniel comma word. Perfect.
So I have to say that the string that the print line method is quite nice.
It's much nicer than the C one to be fair because we don't have to deal with all the formatting specifiers here [sighs] as in C. So in C this is incredibly easy to mess up. Maybe it's also easy to mess up and I'm just using the simplest possible example here in Rust. But so far I like how print line works. But of course, print line is not a reflection of the total programming language. Or maybe actually it is. It could be actually it is actually the print function is quite a good resemblance of what the entire programming language looks like because for example in Python, let's put Python here. The print function looks like this. Print hello like this. In Java it looks like this system out print line and then hello like this.
Then in what else is there in C it's print f. And of course I'm not using any variables to pass here.
It looks like this. It it's somehow somehow it already gives you a feeling of what the of how the programming language is supposed to work like because in Python you have a simple print method and an argument and it's going to be printed and it's even going to be printed in a line. Oh, forgot this one. Okay, now it's complete in Java. Meanwhile, we have this uh we have this way of writing the print line function. Of course, we could also first import system.out, which is the package which contains the print line function, but nobody's ever going to do that. This is the standard way of doing it in Java. So, you already see that Java is a very hierarchical um language. It's very precise. It it consists of or it traditionally uses many packages and subpackages and then you have this print line function and then you have the hello. Okay, fine. In C you use print f which is a print function with a formatting with that allows formatting specifiers and you pass a string. Okay, but you even have to remember the new lines. So you already see Python is as simple as possible. Java is hierarchical and strict and and C is very detailed.
I know this this example is super super super uh superficial but somehow these print functions give you an impression of programming languages even a superficial one.
[snorts] So let's have a look what's the next thing that we can do here. We print something.
We generate a secret number. So let's try to generate a secret number. I'm not going to look too much at the syntax here and just try to compile this and see if we can get a random number here.
Let's call it the random or the rand number and then replace this with rand or maybe let's replace the entire string with something new. So the random number is rand like that.
Close the string. Compile does not work.
Could not compile random due to one previous error. Okay, we have Oh. Oh, that's nice. We have a very clear problem problem description.
The method is available for thread RNG here. H. Okay, whatever that means. I don't know. But it's a very it's a very very verbose error message here. And it even suggests you the fix. That's also the case sometimes in C. Not always.
Perhaps you want to import it. Use rand RNG. Probably that's the line that we were missing. I was missing it intentionally right here. [sighs] We also have to import standard IO. What is that used for? Ah, it's for reading lines from the user later. Okay. So let's try to add here use rand colon rg. What? Wherever that syntax is coming from. Why is a double colon required? This is why is a double colon required?
That's actually a good question. Is there anything about that here?
Well, probably the answer is just that uh double colon follows after the root package. [sighs] I don't know. To me this looks like whenever I see double colons I just think this code is complex even if it's not. I think C++ has some similar syntax that I just hate to see.
So I don't know why I really can't explain it but when I look at C code and al also not always the case when I look at properly written Java code my heart just opens up and is happy when I see properly written C code okay everything is fine but when I see C++ code even if it's properly written I somehow I I just straight out dislike it and I have the same impression about Rust why is it using these colins the colins are somehow unfriendly to me. Don't Why don't you use just a single dot and I don't know there's no technical perspective from me here. Just my personal personal um impression. These double colons make it somehow appear complex to me. What do they even mean? What what is a double colon in in Rust?
In Rust, in the Rust programming pro programming language, clarity and organization are paramount. And one of the key symbols that helps achieve this is the double colon. Wow. This seemingly simple operator. Nobody thinks that's a s seemingly simple plays multiple crucial roles within within Rust's syntax from navigating namespaces to specifying types.
What? Ah, dear Redditor, you are just like me. I found you. Harry Devnull, if you see this or 11 years ago, you probably don't see this video right now, but you are just like me. Why double colon rather than just a dot? I'm just starting Rust.
Why did Rust promote double colon approach?
Using dots seem to be a more natural style. Yeah, maybe it it may be me. I come from Java. Uh [laughter] and languages like Groovy, Scala, and even JavaScript tend to follow the dot approach. Yes, it's just natural. So you have a package dot blah blah blah. Uh and it's the sub package then. Fine. For to me as a programmer, it leaves certain things clear. So I don't have to worry in Rust. When I see the following, I know that F is a strct and X is a member variable. Okay. Moreover, I know that X's value depends on F's value at runtime. What?
I know that Rust is somehow sensitive to the difference between compilation time and runtime. I don't know what's exactly going on there.
So, when we see a dot in Rust, its value, the value of the variable referenced depends on F's value at runtime.
When I instead see the double column, I know that X is an associated constant, a value that is shared by all things of the same type as F.
I know it doesn't matter the data the data f contains.
But what F is I don't understand this sentence here.
I know it doesn't matter the data f contains but what f is so basically it's not runtime uh stuff it's just compilation time stuff it gets even more useful when we get to use methods fx I know that this is calling a method that has f sent as a parameter to it what it's clear that the result of mx depends on what is the value of f.
Now look at the following f col mx. I know that m is an associated function.
[sighs] Reading this stuff makes me prefer the box I encounter in sea. [laughter] I I I feel like I come from the land of freedom and the the land of opportunities which is C to the land of rules and dictatorship which is Rust.
So why do some functions require the use of two columns while others require a dot?
The double colon used for functions in module namespace or double colon is used for functions in module namespace or for static methods.
Dot is used when the method is called in an instance meaning that the first argument is the self. Ah it's like is it like the Python self?
Wait, instance. That sounds a lot like object-oriented programming. An an instance of an of a class.
Let x colon i32. That's probably an integer assigned integer. 32 bits. 5 min.
What?
What's that?
Let x i32 i32 min 57.
Ah, so here let me just make this bigger for you. Maybe this is important to know about rust. I don't know. Um, but it's interesting to see how this programming language works. So here, this is a function call on an instance of something that lives during runtime probably. So we have this five and there's a dot min function that would receive the seven as input but also the five. We could also create a a namespaced method that lives under the 32-bit integer name space that finds the minimum of two numbers and receives those two numbers as input. I find this way more natural.
This is okay. This is more natural. But then why is it so complex? Just import them. I don't get it. Let X. Okay. Okay.
Yeah. Yeah. Yeah. I get it. Rust wants to type everything exactly. So we have a variable. It has an exact type. That's fine. We have we even assign it exactly how many bits it uses.
But then I don't understand why the min function.
No, I I do understand it actually. We have a namespace. We have some kind of module the 32-bit signed integer namespace and under it there's a defined function min that takes in two arguments. Or alternatively we define a 32-bit signed number that is this the result of this. Um but probably because the result of this is expected to be assigned 32-bit number. We know that five must be assigned 32-bit number and then the min function is derived from that.
In anyway this is definitely an area of knowledge that is different from other programming languages.
Okay. So what are we even doing here? We access the name space provided by rand.
Then we use a thread random number generator. There are probably different random number generators and we generate a number between one one dot dot equals 100. What's that syntax?
Why does not why doesn't it just take as input 1 comma 100 and then in the documentation the documentation says the first number is inclusive the last number is exclusive [sighs and gasps] okay so there's some explanation on that the kind of range expression we're using here takes the form start dot dot equals end and is inclusive on the lower and upper bounds.
So we need to specify 1 dot dot equals 100 to request a number between 1 and 100.
Okay. Is there no explanation on on that?
Is that a specific Rust syntax? Rust range.
I is it like ranges in Python?
Okay, this is a Rust range. This is a structure. This looks very C like. So we have a start value and an end value.
It's a range of a specific type and both the start and the end have that specific type and both the start and the end are publicly accessible. This is very much like a mix of C and Java. Here the C is providing the strct the idea of a strruct and then Java is providing this dynamic typing here generic typing.
So this is a range structure and it's it's part of the standard library standard standard Rust ops.
Okay. So it's it's okay. Yeah. Good. Got it.
And then the range is [sighs and gasps] probably what I'm thinking is that the range here this is Rust syntax that automatically knows if we encounter something like this two variables separated by two dots then we convert to this range structure Here I can imagine it. That is how it works.
And then what the Rust tutorial tells us is to use 1 dot dot equals 100. But we could also use 1 do 101 and that would maybe be even simpler. I find this a complication that should only be introduced after in introducing the ranges probably.
[snorts] So where did we stop here?
Okay, so we are trying to generate a random number and print it. Let's try to see it works. If we execute it, the random number is 87. Okay, if I execute it again, 26 79 15 24. Okay, so it's really the case. It really works. We can really generate random numbers. I'm wondering where this where is the function even seated?
Where's the rust function? Where's the rust random number generator even seated? We don't provide a seat here.
For those of you who don't know in C and in other low-level programming languages for random number generators to generate random numbers we need to do an S rand we need to seat the random number. So this is the standard library and sees uh pseudon random number generator because random number generators never really gen generate random numbers. They always need a starting value and from that starting value they derive [sighs and gasps] an a somehow an unpredictable sequence of numbers. It's of course not unpredictable. It's completely deterministic, but it's something that resembles randomness. It's not really random.
Computers are never really random unless you're dealing with quantum quantum computing.
Then here we initialize.
Well, first of all, okay, there's a random number generator function. So random number takes in no input.
Therefore, you have this void argument here and returns an random integer.
But if you use this function, it will return the same value every time you execute your program.
So to fix this you have to pass an initial value to the random number generating algorithm that is called the seat and it's provided via this seat random number generator function. It's where you pass an unsigned int seat here.
Therefore I'm wondering where is the seeding happening in Rust.
The answer is very likely. Probably it's happening under the hood somewhere.
Probably it's based on the time. But if it was based only on the time, then if I executed the same program twice very very fast, for example, if it was based on seconds, so if I execute the same program within a single second, then it would yield the same random number twice. But I don't think that Rust has this problem. Let's check.
Yeah, as you can see the random numbers are really always random. So there must already be taken in some information that is pseudo random that the random number generator uses.
It's quite interesting. So um threat RNG. Let's try to see if we can find out anything about it. That's interesting to me. [sighs] And I know guys, we're not really learning so much about Rust here. Or are we? Actually, we are learning something about Rust. But I'm really that's that's the way I like to to uh explore new topics. It's it's noting something that I'm wondering about and then digging deeper there.
Right? I don't like to to follow tutorials one by one. It's somehow boring. And also somehow it leaves me with too many questions. So I like to dig a bit here. So right now I'm wondering about this random number generator. Where does it get the seat?
Let's just look for a seat here. Aha.
Automatic. Oh wait. The design criteria for thread RNG which we are using here are as follows. Automatic seeding via SIS RNG after every 64 kilobytes of output.
What's SIS RNG?
Is there any other occurrence of seat?
Thread RNG is not automatically receeded on fork.
It is recommended to explicitly call thread RNG receipt. Okay. So if you launch another application from within your Rust program which opens a child process which is called a fork in yeah in computers then that child process probably inherits the same random numbered seat and therefore in this case when you fork your application so that means you open another child process from your application then you should receat. So there are functions to provide a seat and then here what is happening there this RNG is a try RNG interface over the systems preferred random number source.
Okay. So probably operating systems have some kind of preferred random number source. Maybe in Linux it's the random number special file [sighs] and then somehow that is used as a seed or it's used as a source for the random number even I don't know but it looks like we can probably trust it for most random number generating applications.
Okay interesting. So we learned about ranges in Rust. We learned about the random numbers in Rust. We learned about these crates in Rust so far. We learned about the print line and why print line is a macro. Actually, we already learned quite a bunch here. [snorts] And let's also try to to create this guess thing here.
[sighs] So, okay. So, the user can also input a guess. This is interesting, by the way.
I just saw when uh come on well it's interesting to me that these variables here don't have a data type but is it looks like it's possible to provide a data type in Rust because from the Reddit thread we inspected earlier there was a data type provided or specy speified after the variables declaration show. So somewhere there should be some documentation about that right here. Let guess equal an unsigned integer of 32 you and 32 bits.
This is something that I really appreciate. This is something that should be the case in all programming languages in my opinion.
I don't get I I really don't understand programming languages that don't have types.
What's the point? And that's the core reason I never and that's the core reason Python never really clicked with me because in Python you have this principle if it quarks like a duck and walks like a duck then it is a duck. Uh so you can have multiple different classes of objects but if as long as they implement the same methods as long as they share this a same an identical set of methods then they're considered equal in some applications.
But this completely obliterates the ability to know how to pass proper things to functions in my opinion.
did and then it was introduced later into Python the capability to specify types but it's optional.
So in Python a function can accept some kind of object but we it's never it's not even necessarily specified what this object shall be able to do. It's ridiculous in my opinion. How how is anyone supposed to be properly programming with it?
Of course, it is possible. I know there are worldclass programmers using Python, and I'm not I'm not hating on them. I I wish I were them, but I I can't wrap my head around how to properly deal with it. Just tell me what a function is supposed to take as input. And this is right. Just like in Java, just like in any other strongly typed language, we specify exactly.
We have a guess and it's a 32-bit unsigned integer. Perfect.
This is a blessing in my opinion. And then when there's an error somewhere, no, there's not even an error somewhere when we do that because if a function does not return that exact data type or does not accept as input that exact data type, then the then the program won't even compile. Right? So there is a certain level of safety that you don't have in untyped programming languages.
[sighs] So I'm wondering why this tutorial here does not even specify here for the guess that the guess is a string. Of course, it uses the string constructor. So it uses the name function coming from the string name space or module, however you want to call it. But the guess variable is not it's it's not um restricted to only string. So probably we also can't reassign it a number if I understand rust correctly.
Uh wait let's just let's try let's just try to play around with it. So first of all after the use rand RNG we also have to use standard IO as the compiler tells us to do here.
Use standard IO and then we probably succeed in building this and we probably can also execute it. The random number is 97. Okay, perfect. Ah, now we can also input something. So, Daniel, this works.
And let's try to print this.
Print line.
Your input is input like that.
And let's call this guess just input and print here waiting for your input. Okay. So what the program is now doing is nothing because it does not work not found in the scope. Uh of course so where's gas?
Let me just replace that with input here.
Cargo builds that works and executed and that works as well. So we generate a random number then we wait for some input. Let's just write Daniel here and it passes to us your input is Daniel.
What's also nice is that this is a readline function provided by the standard C by the standard Rust library.
I don't know if we have it in in C and C is ridiculously hard to to read a line.
You can't you cannot imagine it because you have to you have to dynamically resize memory depending on the length of the user input but you don't know the size of the user input before processing it. So it's ridiculous. Uh so you dynamically need to expand the size of memory to be able to just read in a simple string. So that's quite nice that we have this read line function here. it expects something and I read about this before a couple of months ago.
If the read line function fails and throws an exception then we need to handle the exception and the exception is handled here. So if read line returns an exception then this expect thing will be called. Yeah. Okay. So every I don't know if every but many functions maybe every come with required exception handling because if we remove this exception handling line here and now try to compile it. Let's see this works. However, there's a warning unused result that must be used.
So, read line has a result and it must be used and it is not used unless we call this expect function and only then it will properly compile successfully without without errors. So, Rust is really trying to force you to properly code.
Um, yeah, I don't know if this is good a good or bad thing. If I just want to hack something um together, then I don't really don't want to deal with exceptions, you know, from my C style or from my C C style from my C style. That sounds incredibly arrogant from the way I write C in projects. I really don't care about exceptions. I Why? Let's imagine just I record 150 episodes on C projects and in every episode I check whether a file has been properly opened, whether memory was properly allocated, whether files were closed, whatever.
It's it's so much overhead for things that really never happen. Of course, it's a different story. If you do things, if you implement things that cannot fail, then it's really nice to force exception handling.
But that's also the case in other programming lang languages. For example, in Java, you somehow have to deal with you somehow have to deal with exceptions at some point.
I I'm not sure if it forces you always to deal with exceptions in Java. Um, and I also don't know how forced you are to deal with exceptions in Rust, but I think you are pretty forced to deal with them.
And anyway, we have learned something here. But one more thing stood out to me. What is this?
So, we create a ah here we create a random number variable.
Let's try to set this variable to 10.
Okay, so we have a variable and we modify it. What happens? Oh, this does not work. Could not compile random due to one previous error.
Cannot assign twice to immutable variable.
And that's an that's an interesting property about Rust. I think I like it.
I don't really have a strong opinion about it but I think I like it. It is that variables are required or variables are by default immutable.
This is super super useful when you are dealing with uh thread safety so parallel programs and it's also to it's also nice to read code see that a variable gets a val a value and then you know that value is never changed that's super nice actually in other programming languages you can enforce that via some keyword for example final or const it is the case by default. That's nice.
So, we cannot reassign this variable.
And I think that this variable here is an explicitly explic explicitly made mutable variable.
So you have by default a constant variable and if you want to make it mutable then you specify mute because here we read line probably into the address of the mutable variable input. This looks like an address operator in C for me.
>> [clears throat] >> So we take as input to this read line function the memory that input points at and then we read the line.
That's interesting because in C that would be a stack variable by the way because it's part of the function of the functions body here.
So the size would be restricted. Somehow re uh somehow Rust is dealing with that.
Did I even did I say at least once in this episode react instead of Rust?
Sorry about that, guys. It's probably been triggering some of you. It's super simple to confuse them. Almost identical languages, React and Rust.
Okay, so we read a line. We make the input explicitly explicitly mutable. I don't know why it's required to specify mute again here because it's already mutable here and then that we then we pass the address off. So the read line function knows where into which part of the memory to read the line contents in into. Yeah, that's interesting.
[sighs] So by default variables are constant but we make them mutable if we explicitly want them to be mut mutable. In other programming language it's the except in other programming languages it's the exact opposite. Variables are no variables are mutable by default. That's why they are called variables in the first place.
>> [gasps] >> And if we want to make them constant, then we specify const or final.
That's an interesting difference.
And is there anything else here? Oh, there's a comparison function here. We check the value of the secret number. This is this is for the secret number guessing game here. So the user inputs a number and tries to guess whether it's bigger or smaller than a specific uh randomly generated guess. Also there's some type parsing here. So the user input which is the guess which is a string is trimmed and then parsed. Then an exception is handled. That's nice.
And then it's passed into this unsigned 32-bit number.
>> [snorts] >> This is all nice. Um, yeah, nice. Is it nice? I wouldn't really like to deal with all of this, but in C it's also quite No, this is way This is way easier than in C to be honest because in C you would have to do What do you have to do in C? You would have to do something like um sprint f.
No. Yeah. Something that is not trivial at all. So I like the avail uh a availability of parsing functions.
That's always of course great.
So it's kind of high level kind of strict and somehow we know that all of this works.
That's yeah expect please type a number.
Okay, you guessed. Guess guess compare secret number. Then there are specific orderings. Those are probably results from the comparison.
This syntax here is very different to what I know from other programming languages except maybe this is the the equivalent to a switch case. the match would be the switch and then those are the different cases and then they are separated out by these arrow operators here. So in case the secret number is less than the user input then we print too small ah no the user input is less than the secret number then we print to small or if it's greater to big or equal you win okay and I guess in the end we also are introduced to a loop oh loop is a loop like this no condition where's the ition.
What?
It's just an unconditional loop here.
Okay, fine. That's interesting.
H [sighs] So, anything else that we can look at here?
I would say I would say that was enough for today's episode, guys.
Let's keep this a surface level Rust exploration.
If you want to see me do something specific in Rust, then let me know in the comments. I really don't know if I like Rust so far. It's it's really unnatural to me to be honest. Um, but still it was an interesting exploration.
We learned some things about about the random number generators about how Rust projects work at the fundamental level um that they are built or managed by cargo and compiled using Rustc and these things. Then we learned about the nature of print line which is a macro to be able to pass in variables directly into the string here which the macro is taken care of. If it was a regular function that would that would be impossible probably.
Then we learned that rust variables are constant by default. They are not mutable. So if we have a mutable variable then we need to make it explicitly m mutable. Otherwise, the compiler will fail. That's a good thing.
Compiler failing always means that errors are caught very early. And then it seems like Rust also has this addressish memory kind of handling that's always that's also prevalent in C. [snorts] And it always forces you to deal with exceptions, which is also quite interesting. So, we learned a couple of Rust concepts here. If you think we should have a deeper look into Rust, then let me know in the comments. And the result of this episode is a it's a nonsensical program. Let's just build it and execute it for one last time. It's just printing a a random number and accepting input. For example, elephant and then printing back that input. So, okay. What [laughter] What I'm So, what am I supposed to do, guys? We just had a nice talk, a nice bros programmer talk here. Hope you enjoyed it. And if you want to support me or if you want to learn low-level programming in general, then I highly recommend you have a look at the nononsense C programming course.
It's linked under the video. It teaches you from ground up how to program things properly in C based on real projects with real exercises. And it really gets you going in low-level C programming from zero.
So, and also what's interesting is that it skips all the boring theory. It's not based on PowerPoint slides like in university lectures. It's all 100% in the terminal. So, it's highly recommended. It's my style of teaching.
I recorded it for guys just like you who enjoy this channel. All right, I enjoy your company. Please put your comments and teach me teach me new stuff. Um, put your opinion there and what you want to see in the next time. Or if you know what else I should explore, then also put that in the comments.
See you next time. Bye-bye.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











