Rust (programming language)

From Simple English Wikipedia, the free encyclopedia
Rust icon

Rust is a programming language designed for systems, which are "software designed to provide a platform for other software".[1][2][3][4] It is or was used to write operating system and web browser components, services such as OpenDNS and Tor, and game engines. It was made by former Mozilla engineer Graydon Hoare.[5]

Software developer Graydon Hoare created Rust as a personal project while working at Mozilla Research in 2006. Mozilla officially sponsored the project in 2009. Since the first stable release in May 2015, Rust has been adopted by companies including Amazon, Discord, Dropbox, Facebook (Meta), Google (Alphabet), and Microsoft.

Applications[change | change source]

Examples[change | change source]

Here is a hello world program in Rust.

// Define entry point.
fn main() {
    // Writes to the output.
    println!("Hello world!");

Here is an example of how to declare a variable, change its value and print its value to the console.

// Define entry point.
fn main() {
    // Assign the value 5 to the variable called x.
    // In Rust, by default, all variables are immutable, which means that their values can't be changed.
    // To make a variable mutable, put the `mut` keyword after the `let` keyword.
    let mut x = 5;

    x = 2;

    // Writes the value of x to the output. 
    println!("{}", x);

Here is an example of using `if`, `else if` and `else` conditionals in Rust.

// Define entry point.
fn main() {
    let x = 5;

    // In Rust, conditions don't have to be in parentheses.
    if x == 5 {
        println!("It's five!");
    } else if x > 5 {
        println!("It's larger than five!");
    } else {
        println!("It isn't equal to five, nor is bigger than five.");

Here is an example of loops in Rust.

// Define entry point.
fn main() {
    let mut counter = 0;

    // Here is a `while` loop.
    while counter < 5 {
        // some code
        counter += 1;

    // Here is a `for` loop.
    for i in 1..10 {
        println!("{}", i); // Prints numbers from 1 up to 9.
    let condition = false;

    // Here is a `loop` loop.
    loop {
        // some code
        if condition {

Here is an example of functions in Rust.

// Define entry point.
fn main() {
    // To specify a data type of a variable, write a colon after the variable name and choose a data type.
    // u8 is a unsigned 8-bit integer, ranging from 0 to 255.
    let x: u8 = 5;
    let y: u8 = 2;

    // Writes the sum of the variables x and y to the console..
    println!("{}", sum(x, y));

In Rust, functions are declared with the `fn` keyword. Parameters are put into the parantheses.
The return type is put after the parantheses and hyphen and right angle-bracket.
If the expression is the last in the function body, it doesn't require a `return` keyword and a semicolon.

fn sum(x: i32, y: i32) -> i32 {
    x + y

References[change | change source]

  1. Klabnik, S., & Nichols, C. (2019). The Rust Programming Language (Covers Rust 2018). No Starch Press.
  2. Blandy, J. (2015). The Rust Programming Language: Fast, Safe, and Beautiful. O'Reilly Media, Inc..
  3. Naugler, D. (2018). An introduction to Rust programming. Journal of Computing Sciences in Colleges, 33(5), 97-97.
  4. Arbuckle, D. (2018). Rust Quick Start Guide: The Easiest Way to Learn Rust Programming. Packt Publishing Ltd.
  5. "The Rust Language | Lambda the Ultimate". Retrieved 2021-04-14.
  6. Blanco-Cuaresma, S., & Bolmont, E. (2016). What can the programming language Rust do for astrophysics?. Proceedings of the International Astronomical Union, 12(S325), 341-344.
  7. Holk, E., Pathirage, M., Chauhan, A., Lumsdaine, A., & Matsakis, N. D. (2013, May). GPU programming in rust: Implementing high-level abstractions in a systems-level language. In 2013 IEEE International Symposium on Parallel & Distributed Processing, Workshops and Phd Forum (pp. 315-324). IEEE.
  8. Hansen, A., & Lewis, M. C. (2016). The Case for N-Body Simulations in Rust. In Proceedings of the International Conference on Scientific Computing (CSC) (p. 3). The Steering Committee of The World Congress in Computer Science, Computer Engineering and Applied Computing (WorldComp).
  9. Antelmi, A., Cordasco, G., D’Auria, M., De Vinco, D., Negro, A., & Spagnuolo, C. (2019, October). On Evaluating Rust as a Programming Language for the Future of Massive Agent-Based Simulations. In Asian Simulation Conference (pp. 15-28). Springer, Singapore.
  10. Blanco-Cuaresma, S., & Bolmont, E. (2017). Studying tidal effects in planetary systems with Posidonius. A N-body simulator written in Rust. arXiv preprint arXiv:1712.01281.