Rust (programming language)
Appearance

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
- Astrophysics[6]
- GPU programming[7]
- Simulation[8][9][10]
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 called 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);
}
Here is an example of a function that returns sum of two numbers in Rust.
// Define entry point.
fn main() {
// Declares two variables with the data type of signed 32-bit integer.
let x: i32 = 5;
let y: i32 = 2;
// Prints the sum of the variables x and y.
println!("{}", sum(x, y));
}
/*
The `fn` keyword is used for defining functions, which is followed by the name of the function.
Parameters are written in the parantheses, and are followed by a colon and its data type.
A data type of the returned value is put after the hyphen and right angle bracket.
If the expression is the last thing in the function's body, you don't need to use the `return` keyword and a semicolon.
*/
fn sum(x: i32, y: i32) -> i32 {
x + y
}
References
- ↑ Klabnik, S., & Nichols, C. (2019). The Rust Programming Language (Covers Rust 2018). No Starch Press.
- ↑ Blandy, J. (2015). The Rust Programming Language: Fast, Safe, and Beautiful. O'Reilly Media, Inc..
- ↑ Naugler, D. (2018). An introduction to Rust programming. Journal of Computing Sciences in Colleges, 33(5), 97-97.
- ↑ Arbuckle, D. (2018). Rust Quick Start Guide: The Easiest Way to Learn Rust Programming. Packt Publishing Ltd.
- ↑ "The Rust Language | Lambda the Ultimate". lambda-the-ultimate.org. Retrieved 2021-04-14.
- ↑ 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.
- ↑ 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.
- ↑ 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).
- ↑ 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.
- ↑ 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.