This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static N: i32 = 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let x = true; | |
let y: bool = false; | |
// ⭐️ no TRUE, FALSE, 1, 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let x = 'x'; | |
let y = '😎'; | |
// ⭐️ no "x", only single quotes | |
//because of Unicode support, char is not a single byte, but four. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = [1, 2, 3]; // a[0] = 1, a[1] = 2, a[2] = 3 | |
let mut b = [1, 2, 3]; | |
let c: [int; 3] = [1, 2, 3]; //[Type; NO of elements] | |
let d: ["my value"; 3]; //["my value", "my value", "my value"]; | |
let e: [i32; 0] = []; //empty array | |
println!("{:?}", a); //[1, 2, 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = (1, 1.5, true, 'a', "Hello, world!"); | |
// a.0 = 1, a.1 = 1.5, a.2 = true, a.3 = 'a', a.4 = "Hello, world!" | |
let b: (i32, f64) = (1, 1.5); | |
let (c, d) = b; // c = 1, d = 1.5 | |
let (e, _, _, _, f) = a; //e = 1, f = "Hello, world!", _ indicates not interested of that item | |
let g = (0,); //single-element tuple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a: [i32; 4] = [1, 2, 3, 4];//Parent Array | |
let b: &[i32] = &a; //Slicing whole array | |
let c = &a[0..4]; // From 0th position to 4th(excluding) | |
let d = &a[..]; //Slicing whole array | |
let e = &a[1..3]; //[2, 3] | |
let e = &a[1..]; //[2, 3, 4] | |
let e = &a[..3]; //[1, 2, 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = "Hello, world."; //a: &'static str | |
let b: &str = "こんにちは, 世界!"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Hello world function | |
fn main() { | |
println!("Hello, world!"); | |
} | |
//Function with arguments | |
fn print_sum(a: i8, b: i8) { | |
println!("sum is: {}", a + b); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn plus_one(a: i32) -> i32 { | |
a + 1 | |
} | |
let b = plus_one; | |
let c = b(5); //6 | |
let b: fn(i32) -> i32 = plus_one; //same, with type inference | |
let c = b(5); //6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Line comments | |
/* Block comments */ |