Rust Lang in a nutshell

StackOverflow's developer surveys have shows Rust to be the most loved language in the last couple of years. Infact, Deno is written in Rust! Here's why:

  • Rust is a statically typed but intelligent enough to decipher types of variables where they aren't explicitly typed.

  • Immutable variables by default. This ensures that data cannot be changed by functions unless you specially mark the variable as such.

  • Ownership and borrowing of variables is the most important concept in Rust. It's also what leads to a higher learning curve. Each value is "owned" by the variable that is destroyed when it goes out of scope.

  • When a new variable is assigned to the old one, the old reference is destroyed. Let's take a look at an example

    let s1 = "Hello world".to_string();
    let s2 = s1;

    s1 will cease to exist. The value of s1 gets transferred to s2.

  • A variable can also borrow the value from the owner. Borrowing is simply a pointer reference to the original data. Strict rules govern this act. For example, the borrower cannot outlive the owner in scope.

  • While this concept is a little weird, it prevents null pointer exceptions, dangling pointers and buffer overflows.

Given it's type safety and emphasis on data security, I think Rust will be the language to look out for in the next 5 years, or till another language is invented to take it's place.

Full Post here, 20 mins read