Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

HF Rulez the UniverseHF Rulez the Universe
Guest
programming Rust helloworld

Intro in writing code in Rust

Posted Oct 11, 2023 10:35 PM
We will write our first program in Rust. The commands used in terminal below are used in bash.

Step 1 :

Install Rust by going to this website and following the installation instructions:Install Rust

Step2:

open terminal and write this command to create a new project:
Code
cargo new hello_world

now we created our project. This command creates a folder name hello_world and inserts required
files in this folder to be used when compiling the program.

Step 3:

We will now run this command:
Code
cd hello_world

this command just opens up the folder and takes us inside that folder in the terminal.

you will need to open up the file called "src/main.rs" You can use your favorite text editor or IDE.
I will not go into specifics on what to use to edit this file. It can be any text editor or IDE.

Now once open you will want to replace all the code inside the file with this:

Code
fn main() {
    println!("Hello, World!");
}

fn means fuction and main() is like in most programming language is that starting point of a program.
println! is a built in fuction that will print the text to screen. This is similar to the c and c++ languages.
for c it's printf for c++ it's cout but using string header files.

there you go.

Step 4:

We will compile and run the program.

you do this by using the commands:

Code
cargo run

in terminal while in the folder hello_world. Also make sure you don't rename the file "src/main.rs"

This should compile the program and run it. You should see the words hello world printed on the terminal screen.

these commands used are for bash.

I am starting to lean how to code in Rust. It's said to be the most quickest way to code projects and the most secure meaning it will handle common well known security issues in code like buffer overflows automatically when it gets compiled. This is what is said about it and most that I heard said this is the future. They feel it will replace c and c++ and most languages.

What can you do with Rust?

You can do anything.

You can do systems programming which means writing your own OS, drivers, windows programs, linux programs, aka software.

web apps: this means you can do the same things as PHP using it as a backend to communicate with software like databases etc. Also frameworks to make it work like an app kinda like java embedded into a page.
One example of this framework is : Rocket Framework

There's webassembly which is a virtual machine for the web browser. Similar to java but this allows you to have low level access and you can write small apps or programs. You can read more here: Web assembly

You can use Rust for game development here's a game engine: Rust Game Engine

You can write networking software and tools.

You can write malware, and even embedded systems.

A good example of using Rust to make programs and code for embedded systems would be Tock OS

Tock embedded OS is written in Rust and is meant for embedded systems commonly used in devices that are IOT internet of things devices.

Pretty much you can write anything in this language. There's really no limits. It's slowly growing in popularity.
I am right now learning the language and trying to see if all these are legit. I have coded in C and C++.
I have written a bootloader in ASM x86 .

So, I thought why not write a blog about an intro to Rust. That's just incase anyone else is interested in the language and learning it. I don't have an opinion about it. However, from other others have said this language is of the future. I personally can see this if what they say is true. If it eliminates common security issues like buffer overflow. This would for sure replace all languages in the professional world and that's due to the fact that it would at least eliminate security issues that we already know what programmers shouldn't do. It allows you to spend more time and focus on just writing your project or app rather then spending time to check and double check your work making sure you didn't make any beginners mistake. This for companies ensures the people they hired even if they know about the security issues like buff overflow etc. It just gives that extra layer knowing that those security holes won't be a thing anymore. It's a costly mistake when you put your program into production and then find these issues out later.

Hope this helps in any way thanks and have a lovely day and keep on coding my friends. 😎