Rust. How to start a project in

Rust is a programming language that is becoming more and more popular among developers. But what would be the reason for such success? The language is originally recognized for safety and performance, So, if you are new to programming and want to know more about this language created by Mozilla, how about read this material till the end?

There is an increasing number of companies interested in Rust Developers. Simply find job openings for DEVs (Vaultree Incorporated). In addition, the language has become popular with DEVs because of its advantages.

What is Rust?

In this article I explained why Rust is the most preferred programming language.

In short, Rust is a multi-paradigm and compiled programming language. It was developed by Mozilla Research. Its core principles are concurrency without data contention, abstraction without overhead, and security without garbage collectors. It can be used in a variety of applications, such as:

  • command line tools;
  • Tools for DevOps;
  • Web Services;
  • Play;
  • IoT (Internet of Things) application.

Launched in 2010 with open source, the language is said to be like the new fabric C++, as the two technologies are very similar, although Rust is more efficient in terms of security.
Out of curiosity, rust in Portuguese means “rusty”, but in general it is not “rusty”, as it is constantly being updated and is quite competitive in the market.

How was rust created?

The development of Rust began in mid-2006 during the spare time of Graydon Hoare. At the time, he was working at Mozilla, and the company ended up taking interest in a new language that was similar to C++, but had more advantages.

Thus, Mozilla decided to invest in the project and hired a team of technicians to dedicate Hoare more deeply to the new language. Its first version was released in 2010 and became open-source in no time. Soon after, Hoare left the project’s technical leadership, justifying that he was suffering from burnout (a syndrome associated with extreme fatigue) and began dedicating himself to other smaller companies. But in mid-2016, he accepted a job offer from Apple Inc. to work on the development of the Swift language.

Who Uses Rust Language?

As you have seen, the creation of the language was a major achievement for Mozilla, which was soon used by many other companies.
Thus, software that is widely used today, such as Firefox, Dropbox, Yelp, FireCracker (the visualization technology used by Amazon) and Cloudflare use Rust.
But, moreover, it is present in many projects of companies and startups that want measurable results while prioritizing security and performance.

What makes this language different?

Did you know that according to Stack Overflow surveys, between 2016 and 2020, the Rust language was considered the preferred language among developers? But what is the explanation for this foreshadowing? Here are some benefits of rust. Remember that this does not mean that it is unanimous among developers, but it does indicate that it is very important to devote yourself to studying this language to keep this gap in your curriculum and to belong to this powerful community. is important.

performance

During the compilation process, Rust does the memory management itself, freeing up space until it is occupied by variables that are not being used. In other languages, this function is performed by the garbage collector, so Rust exhibits greater performance, as it allows for greater speed in development.

Security

Whenever a variable is no longer used by the application, it is automatically deallocated by the language’s memory management system. This avoids errors and poor performance.

productivity

The developer who chooses Rust gains in productivity. Firstly, because the language has very extensive documentation and is full of details about its usage. Secondly, because it is able to identify errors that other languages ​​do not, thanks to its intelligent compiler.

Update

One of the benefits is also the constant updating, which improves the features of the language. One of the most recent is from April 2019. It has improved languages, making them easier to read and write.
In addition, the Rust language also performs well in web applications due to its resourcefulness and high performance, giving projects greater agility.

career

Overall, the Rust developer space is hot in the market. This is because startups and companies are looking for more agile and secure systems to enhance their results.

Installation and Development Environment

To get started with Rust we have two options, or using the Play Rust site which is maintained by Rust core and it is a very good and very complete tool or by downloading the Rustup tool which is the official Rust installer. Installation will depend on your operating system, but it is very easy, on the official website we can find these options mentioned above.

I would choose install as it gives us more options. I would use VS Code as a code editor, the installation is very easy, on Windows it is an executable, and if you are using a Unix-based system, I recommend you to download it via Snap. I give advice

Below are the extensions I currently have installed within VS Code:

Rust Pack – This pack has 3 main extensions that I used.
Rust Doc Viewer – to facilitate documentation.

For these studies I will use the stable version of Rust, after installing Rustup, we run the command:

rustup default stable

Through this command we set the stable version as default. Additionally, we have the option to use Nightly which is updated more frequently with the latest features in the language.

The stable version is released every 6 months.

To update and download updates for Rust, Cargo and Rustup tools, we run the command:

rustup update stable

And thus we have an environment ready to start coding.

hello world

In the directory of your choice we will create a file called hello_world.rs (.rs extension is the Rust file extension).
The following content will be added inside this file:

fn main() {
    println!("Hello World!");
}
enter fullscreen mode

exit fullscreen mode

fn

→ Language’s reserved word, every function creation within Rust we will use this keyword.

Main()

→ Every binary program in Rust has an entry point, where the execution of the program begins, every time we run a program, this will be the starting point. By default this function takes no parameters and returns nothing.

,

→ function scope – everything between the pair of braces is the body (scope) of this function.

Println!

→ This is a macro (we’ll see what a macro is in another post), but in essence it will be a code template for us to use, and the compiler will evaluate it in pre-compile. Anything that has a macro at the end of the !() command. For better readability as we can see in this line 4 spaces indentation was used, Rust style is indenting four spaces, not tabs.
(“Hello world!”);

→ Every string inside Rust must be enclosed in double quotes (“”), single quotes are used only in character types (”). This line must be terminated with a semicolon to indicate that this expression has ended, and if we have the next one, it is ready to begin. Most lines of Rust code end with a semicolon.

program execution

Before executing a program in Rust, we need to compile it, that is, generate a file that the computer knows to execute, for this we go through the Unix terminal and enter that directory where we have created the file, executing the following instruction:

cd /dev/workspace/rust

and from command prompt on windows:

cd \dev\workspace\rust

This is the path where I created the file, you will change this line by adding the path you created.

After that, compile the file by running the command below in terminal:

rustc hello_world.rs

The file we created inside the directory will generate another one, which will be executable, for Windows it will be a hello_world.exe and for Unix systems a hello_world.sh. On Windows a file named hello_world.pbd will also be generated, this file contains debugging information.

To play a file on Windows, let’s run the command:

.\hello_world.exe

To run the file on Unix, let’s run the command:

./hello_world

The output will look something like this:

Hello World!

So that this post doesn’t get too long, I’ll leave building the Rust project for the next one, where we’ll start using the Cargo tool.

Voila! You have your first Rust project. In the next article we will talk about this language in more detail about what you can create using it. see you!

Vaultree. about

Voltree’s encryption-in-use enables businesses of all sizes to process (search and compute) encrypted data completely end-to-end without needing to decrypt it. Easy-to-use and integrated, Vaultry delivers peak performance without compromising security, neutralizing the weak spots of traditional encryption or other privacy-enhancing technology (PET) based solutions. follow waltry Twitter (@Vaultree), LinkedIn, Reddit (r/Vaultree) or dev.to. To stay up to date on product development and company news, visit www.vaulttree.com, and sign up for product demos and our newsletter.

Leave a Comment