Top 1,000 Features Creators Events Podcasts Extensions Interviews Blog Explorer CSV

Rust

< >

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

#20on PLDB 14Years Old 357kRepos
Download source code:
git clone https://github.com/rust-lang/rust
Homepage · Leet Sheet · REPL · Try It Online · Source Code · Blog · Wikipedia · Subreddit · Twitter · FAQ · Docs

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 Example Token
Standard Library
println!("Hello, World!");
Conditionals
Constants
While Loops
Booleans true false
Line Comments
// A comment
//
Type Inference
Print() Debugging
println!("Hi");
println!
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 · About · Resources · Acknowledgements · Part of the World Wide Scroll