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:

Nesse ano, palestrei na APIX sobre microsserviços. Abaixo, registro em vídeo feito pela organização do evento. Comentários? Feedback?
That is a question that I have been answering for years. The answer is an emphatic “NO” in most cases....
Há tempos que percebo em mim a ocorrência de um padrão recorrente. Não acho que ele seja exclusividade minha, mas,...
A EximiaCo não vende! Quando planejei a empresa decidi que ela não teria um departamento comercial. A estratégia é buscar...
Time to study again. I just started an online course at the Singularity University. If you could solve one of...
Há anos eu conheço e aceito a ideia de que devemos buscar melhoria contínua. Sei que é natural e aceitável...

Inscrição realizada com sucesso!

No dia da masterclass você receberá um e-mail com um link para acompanhar a aula ao vivo. Até lá!

A sua subscrição foi enviada com sucesso!

Aguarde, em breve entraremos em contato com você para lhe fornecer mais informações sobre como participar da mentoria.

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:

× Precisa de ajuda?