Jump to content

Rust (programming language)

From Simple English Wikipedia, the free encyclopedia
Revision as of 18:01, 18 December 2022 by 147.161.27.97 (talk) (Adding more examples.)
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]

Applications

Examples

Here is a hello world program in Rust.

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

Here is an example of declaring a variable and writing its value to the output in Rust.

// Define entry point.
fn main() {
    // Assigns value 5 to the variable callex x.
    let x = 5;

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

Here is an example of using if-else statement in Rust.

// Define entry point.
fn main() {
    // Assigns value 5 to the variable callex x.
    let x = 5;

    // Checks if the variable x is equal to 5, if it isn't, the code in the else block will execute instead.
    if x == 5 {
        println!("x is a 5!");
    } else {
        println!("x is not a 5!");
    }
}

Here is an example of using a loop statement that breaks after it reaches 7 in Rust.

// Define entry point.
fn main() {
    // Assigns value 0 to the variable called x.
    let counter = 0;

    // "Loop" loop runs forever until it reaches a break.
    loop {
        if counter == 7 {
            break
        }

        // Increases the value of counter by 1.
        counter += 1;
    }

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


References

  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". lambda-the-ultimate.org. 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.