Measures Concepts
GitHub icon

Rust

Rust - Programming language

< >

Rust is an open source programming language created in 2010 by Graydon Hoare.

Source code:
git clone https://github.com/rust-lang/rust
#24on PLDB 14Years Old 357kRepos

Try now: Riju · TIO · Replit

Rust is a systems programming language sponsored by Mozilla Research, which describes it as a "safe, concurrent, practical language," supporting functional and imperative-procedural paradigms. Rust is syntactically similar to C++, but its designers intend it to provide better memory safety while maintaining performance. Rust is an open source programming language. Read more on Wikipedia...


Example from Compiler Explorer:
// Type your code here, or load an example. pub fn square(num: i32) -> i32 { num * num } // If you use `main()`, declare it as `pub` to see it in the output: // pub fn main() { ... }
Example from Riju:
fn main() { println!("Hello, world!"); }
Example from hello-world:
fn main() { println!("Hello World"); }
// Hello world in Rust fn main() { println!("Hello World!"); }
Example from Linguist:
extern crate foo; extern crate bar; use foo::{self, quix}; use bar::car::*; use bar; fn main() { println!("Hello {}", "World"); panic!("Goodbye") }
abstract alignof as become box break const continue crate do else enum extern false final fn for if impl in let loop macro match mod move mut offsetof override priv proc pub pure ref return Self self sizeof static struct super trait true type typeof unsafe unsized use virtual where while yield

Language features

Feature Supported Token Example
Conditionals ✓
Constants ✓
While Loops ✓
Booleans ✓ true false
Line Comments ✓ //
// A comment
Type Inference ✓
Print() Debugging ✓ println!
println!("Hi");
Pattern Matching ✓
Operator Overloading ✓
Macros ✓
// https://doc.rust-lang.org/book/ch19-06-macros.html
#[macro_export]
macro_rules! vec {
    ( $( $x:expr ),* ) => {
        {
            let mut temp_vec = Vec::new();
            $(
                temp_vec.push($x);
            )*
            temp_vec
        }
    };
}
Iterators ✓
for n in 0..42 {
  println!("{}", n);
}
File Imports ✓
use ::std::fs;  // Imports from the `std` crate, not the module below.
use self::std::fs as self_fs;  // Imports the module below.
mod my;
use self::foo::Zoo as _;
#[path = "foo.rs"]
mod c;
Directives ✓
// A conditionally-compiled module
#[cfg(target_os = "linux")]
mod bar {
    /* ... */
}
// General metadata applied to the enclosing module or crate.
#![crate_type = "lib"]
// A function marked as a unit test
#[test]
fn test_foo() {
    /* ... */
}
// A lint attribute used to suppress a warning/error
#[allow(non_camel_case_types)]
type int8_t = i8;

// Inner attribute applies to the entire function.
fn some_unused_variables() {
  #![allow(unused_variables)]

  let x = ();
  let y = ();
  let z = ();
}
MultiLine Comments ✓ /* */
/* A comment
*/
Comments ✓
// https://doc.rust-lang.org/reference/comments.html
// a comment
Strings ✓ "
"hello world"
Case Insensitive Identifiers X
Semantic Indentation X

View source

- Build the next great programming language · Search · Add Language · Features · Creators · Resources · About · Blog · Acknowledgements · Queries · Stats · Sponsor · Day 605 · feedback@pldb.io · Logout