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:

Decidi aprender a programar com R. Aqui está algo que escrevi. ## defining a function makeCacheMatrix <- function(x = matrix())...
Confesso que estava sentindo falta de escrever em primeira pessoa. Há tempos, publicando apenas nos sites da EximiaCo, não encontrava,...
Há algum tempo, estou compartilhando recomendações práticas para construção de microsserviços com Aspnet Core.  Agora, resolvi organizar meus exemplos para...
Pessoas diferentes têm realidades diferentes e, por isso, são impactadas pela crise de maneiras diferentes. Tenho consciência de que meu...
Este é o primeiro post de uma série onde pretendo compartilhar, com considerável nível de detalhe, como resolver problemas de...
Sometimes we want to write functions that may not always return a result. In these cases we can use the...
Oferta de pré-venda!

Mentoria em
Arquitetura de Software

Práticas, padrões & técnicas para Arquitetura de Software, de maneira efetiva, com base em cenários reais para profissionais envolvidos no projeto e implantação de software.

× Precisa de ajuda?