Skip to content

Unisergius/rust-7-april-fcc-ikea

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Rust - fCC Meetup in Ikea Algarve - 12th April 2023

Guidelines to get hands on into Rust.

Rust is here. Why should I care about it?

  • Concurrency, Safety, Speed. How?
  • Safety AND Speed
  • No Garbage Collector
  • Excellent memory manager sifting the program using Stack and Heap data structuring.
  • Ownership and Borrow Checker
  • And other things like being Easy to compile it to WebAssembly, immutability by default, detailed type annotations...

Ownership and Borrow Checker - A very important concept to understand in RUST

That's too many good news. What's the catch here?

Some of the red dots on Rust.

  • All these new paradigms can be a bit complicated and slow you down into creating new stable products
  • Learning curve is steep
  • Community has some room to grow
  • Get ready for a somewhat ugly syntax.

But what should I do with Rust exactly? Is it a good language for Start Ups to choose?

Rust Packages Index Website

You can browse Rust Libraries here:

Getting Started

Requirements

MacOS needs xcode and corresponding development tools:

  xcode-select --install

Windows:

  • ¯\(ツ)

Linux needs gcc installed. Depending on your system package manager you'll probably have the package gcc available to install.

APT Example :

  sudo apt install gcc

Install Rust

This fetches the installer and pipes the downloaded file into executing it. It will install Rust and Cargo. Cargo is Rust's package manager.

  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 

By the end the installer will show you this message:

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source "$HOME/.cargo/env"

It's important that your path recognizes Rust folder for executables "bin". So if you're command lines are not being recognized, please check your PATH env variable.

Update Rust

Type the following command to update Rust. (Also to check if your terminal recognizes your updated PATH env var)

  rustup update

What Rust brings to the table

Rust compiler is very elaborate in showing you what your program does wrong.

For example, let's do something we'd usually do on javascript into a file called im-coding-js-in-rust-lol.rs .

  function slapSomeone(yourName, targetName) {
    return yourName + " slaps " + " around a bit with a large trout";
  }

Try to compile this. you already know it's not going to run. But see if you can correct the program without resorting any stack overflow shenanigans. Rust compiler should illustrate problems like it's the van gogh of ascii characters.

  rustc im-coding-js-in-rust-lol.rs

All variables are immutable by default.

The value initialized into the variable cannot be changed unless specifically specified.

fn main() {
    let x = 5;
    println!("The value of x is: {x}");
    x = 6;
    println!("The value of x is: {x}");
}

This will give you a compile time error. See if you can make this program work out.

Data types are special annotations that you can specify after the variable. They can be inferred by its initial value or you can specifically tell them what they are.

  let a = 2; //i32
  let b: i32 = 2;

The list of types you can annotate are here

Strict scope rules

Like in many modern iteration of languages, for you to use a function you need you need to declare that you're using it. You need to include it on the scope you're working.

Example

use std::cmp::least;

Ownership

What's Next:

Rust eBooks

Rust website offers you 3 approaches:

  • Book
  • Rustlings Course
  • By Examples

Book

Get book. Must read non-fictional book.

This gives your the basics. Instalation, Cargo package manager, your first program with user interaction. And then much much more.

Rustlings

Rustlings is an open source project you can clone to do Rust exercises:

By Example

A list of examples in Rust, demonstrating most Rust's programming courses .

HackerRank

After these exercises you can start doing basic HackerRank exercises to up your Rust face on:

Rust Frameworks

Actix Web - Web Framework

Axum - Web Framework

Yew - Frontend Framework

Rocket - Web Framework

Web Framework Listings

Bevy - Game Engine

Amethyst - Game Engine

List of Game Engines

Rust Project

Building a calculator in Rust

Articles about Rust

About

Guidelines to get hands on into Rust.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published