Last active
April 26, 2017 20:50
-
-
Save marti1125/ab3ab97b3419e138727873d3e564e2ef to your computer and use it in GitHub Desktop.
Rust - Tipos de variables
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
// Functions | |
pub fn suma(a: i32, b: i32) -> i32 { | |
a + b | |
} | |
fn resta(a: i32, b: i32) { | |
let r: i32 = a - b; | |
println!("Result {:?}", r); | |
} | |
// Variable Bindings | |
fn main { | |
let a = 5; | |
let mut b: i32 = 4; | |
b = 10; | |
let (x, y) = (5, 6); | |
} | |
// Primitive Types | |
fn main { | |
// Booleans | |
let x = true; | |
let y: bool = false; | |
// Char | |
let x = 'x'; | |
let two_hearts = '💕'; | |
// Numeric | |
let a = 5; | |
let y = 1.0; //64-bit floating f64 | |
//Array | |
let mut m = [1,3,5]; | |
m[0] = 1; | |
m[1] = 6; | |
println!("Array {:?}", m); | |
// Slice Array | |
let a = [0, 1, 2, 3, 4]; | |
let complete = &a[..]; | |
let middle = &a[1..4]; | |
println!("Complete {:?}", complete); | |
println!("Middle {:?}", middle); | |
// Tuples | |
let tuple = (1, "hello"); | |
let b: (i32, &str) = (1, "hello"); | |
let x = tuple.0; | |
let y = tuple.1; | |
println!("x es {}", x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment