Getting started with Rust

I believe that, from time to time, it is interesting to learn a new language or framework that takes us out of our comfort zone. So I decided to learn Rust (Ok! I confess I was influenced by Ayende).

Why Rust?

Programs written in Rust are blazingly fast and memory-efficient. Rust programs are memory-safe and thread-safe. Also, the compiler is excellent and help us to fix bugs quickly.

Another good reason? Hundreds of companies have adopted rust.

Finally, it is nice to learn a language that really challenges C++.

How to start?

If like me, you know nothing about Rust, I strongly recommend you to read the excellent “The Rust Programming Language” book which is available for free online.

The first chapter will teach you how to get it and to write your first program.

The following code comes from the book, by the way.

use std::io;
use std::cmp::Ordering;
use rand::Rng;

fn main() {
    println!("Guess the number!");

    let secret_number = rand::thread_rng().gen_range(1, 101);

    loop {
        println!("Please input your guess.");

        let mut guess = String::new();

        io::stdin().read_line(&mut guess)
            .expect("Failed to read line");

        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };

        println!("You guessed: {}", guess);

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big!"),
            Ordering::Equal => {
                println!("You win!");
                break;
            }
        }
    }
}

Even simple, this program shows features that I loved like immutability, variable name shadowing, pattern matching and more.

It is time to move on

In future posts I will solve classic computer science problems using Rust.

Stay tuned!

Compartilhe este insight:

Elemar Júnior

Sou fundador e CEO da EximiaCo e atuo como tech trusted advisor ajudando diversas empresas a gerar mais resultados através da tecnologia.

Elemar Júnior

Sou fundador e CEO da EximiaCo e atuo como tech trusted advisor ajudando diversas empresas a gerar mais resultados através da tecnologia.

Mais insights para o seu negócio

Veja mais alguns estudos e reflexões que podem gerar alguns insights para o seu negócio:

Last post, I asked an explanation about the execution result of the following code. using System; using System.Threading.Tasks; using static...
This is the first of a series of blog posts sharing some knowledge about how to develop a real-world software...
Mais cedo, uma de minhas parceiras de negócio entrou em contato comigo pedindo uma “ajudinha rápida”. Respondi para ela que...
Sou extremamente privilegiado por ter em minha rede de contatos gente extremamente qualificada e competente no que faz. Conversar com...
A música é conhecida e todos sabem que ela encerra com uma nota alta. Mesmo assim, a execução de “Phantom...
Some days ago, I heard a fantastic interview with Phil Haack on the IT Career Energizer Podcast. Here is the...

Crie sua conta

Preencha os dados para iniciar o seu cadastro no plano anual do Clube de Estudos:

Crie sua conta

Preencha os dados para iniciar o seu cadastro no plano mensal do Clube de Estudos:

Mentoria em
Arquitetura de Software
com ênfase em IA

Aprenda a coordenar equipes de desenvolvimento, aplicar padrões e técnicas de arquitetura e aumentar sua produtividade criando sistemas inovadores com o suporte da IA.

× Precisa de ajuda?