Last active
May 25, 2018 16:36
-
-
Save henryaj/2cbf1b3e7a6fb726c5e6921fd787f58f to your computer and use it in GitHub Desktop.
Rust experiments
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
use std::fmt; | |
struct Matrix(i32, i32, i32, i32); | |
impl fmt::Display for Matrix { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
let result = format!( | |
"{0}, {1}, {2}, {3}", | |
self.0, self.1, self.2, self.3 | |
); | |
write!(f, "{}", result) | |
} | |
} | |
fn main() { | |
let m = Matrix(432,293,120,94); | |
println!("{}", m); | |
} |
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
fn reverse(pair: (i32, &str)) -> (&str, i32) { | |
let (a, b) = pair; | |
(b, a) | |
} | |
fn main() { | |
let my_favourite_tuple = (1u32,2u32,3u32,"hello",'a'); | |
// u cant just print dis | |
// as the tuple doesn't implement the proper trait | |
// println!("{}", my_favourite_tuple); | |
// gotta extract elements | |
println!("{}", my_favourite_tuple.3); | |
let pair = (0, "sup"); | |
println!("pair: {:?}", pair); | |
println!("reversed pair: {:?}", reverse(pair)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment