Rust is what is known as a systems programming language. It is called this because it natively has all the features that would make it a great tool for building an operating system.
I will cover these in more detail in the rest of this article.
Functional and Procedural
I will explain both these terms in more detail in other sections of this series, for now here is what you need to know;
The functional part in Rust basically says that functions (groups of code) are treated as first class citizens and are able to be passed around. If I had a function to add two numbers together, and another function needed to be able to know how to do that, I can easily share that information.
The procedural part is fairly similar, it basically means that we write our code in chunks that are meant to be run in a particular way.
We we might have 6 procedures and they can be called when we need them. These procedures don’t have any special access to data that isn’t passed into them, much like formula in school you need to feed it all the inputs.
Rust is a compiled language – this means that before you try and execute your code you need to compile it ahead of time. This means taking the code you have written and running it through another program which can turn your code into machine code (code which can be read by machines).
Rust is quite interesting because the Rust compiler is written in Rust. This means that when you run the steps to turn your code from something you understand to something the computer understands, the code that does that transformation is itself Rust.
Here is the common “Hello, world!” example in Rust.
Here we see a function called
main (which we can deduce is the main program we want to execute) and it is calling a macro called
println!. From other programming languages I know this stands for Print Line. And then we have the string “Hello, world!”.
It is one of the less intimidating Hello, World! examples I have seen.
Rust’s concept of Ownership and Borrowing
The Rust language relies heavily on the concepts of Ownership and Borrowing. It is how it can boost being so memory safe.
A function owns a resource and when you are done with the resource it is deallocated. This means if something else references a resource and that resource is deallocated, that reference will no longer be valid.
You can give a resource to a function, but this means you no longer have it and can’t access it.
The concept of borrowing basically says. I will give you access to this resource, but when I want it back you have to give it to me.
Rust is popular and the community seems to be growing in number and in voice continually. There is a well used Rust Subreddit and plenty of questions and answers on Stack Overflow
If you want to learn more, there is a free online book about Rust.
This is part of our Simple CS series, where we explain Computer Science and Web Development terms in really simple language. Excellent for beginners or if you just need a quick refresher.
Access to the series is completely free, if you have found it useful we would really appreciate it if you could let people know about the project.
If there is a term you would like me to cover please drop us an email.