Created
October 30, 2022 20:33
-
-
Save Clivern/11aae2ff6d798cbdbcb07c2272df86c1 to your computer and use it in GitHub Desktop.
Rust Basics
This file contains hidden or 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
const MAX_ITEM1: i64 = 1000000; | |
const MAX_ITEM2: &str = "HJ"; | |
fn main() { | |
let y = 3; | |
println!("y = {}", y); | |
let mut x = 1; | |
x += 1; | |
println!("x = {}", x); | |
println!("MAX_ITEM1 = {}", MAX_ITEM1); | |
println!("MAX_ITEM2 = {}", MAX_ITEM2); | |
let msg = "Hello World"; | |
println!("{}", msg); | |
// Shadowing | |
let h = 2; | |
println!("h before = {}", h); | |
let h = "h"; | |
println!("h after = {}", h); | |
/* | |
Data Types | |
---------- | |
Signed Integers --> i8, i16, i32, i64, i128, isize | |
Unsigned Integers --> u8, u16, u32, u64, u128, usize | |
floats | |
boolean | |
*/ | |
let a: i32 = 2; | |
let b = 24i64; | |
println!("a = {}", a); | |
println!("b = {}", b); | |
let c: bool = true; | |
let d = if c { "c is true" } else { "c is false" }; | |
println!("d = {}", d); | |
let mut e = 1; | |
let f = loop { | |
e += 1; | |
if e == 10 { | |
break "e is 10"; | |
} | |
}; | |
println!("e = {}", e); | |
println!("f = {}", f); | |
println!("test1(1., 2.24) = {}", test1(1., 2.24)); | |
} | |
fn test1(a: f64, b: f64) -> f64 { | |
a + b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Playground -> https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6f231d50947f1ec4f2553d483b879bce