Skip to content

Instantly share code, notes, and snippets.

@henryaj
Last active May 25, 2018 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryaj/2cbf1b3e7a6fb726c5e6921fd787f58f to your computer and use it in GitHub Desktop.
Save henryaj/2cbf1b3e7a6fb726c5e6921fd787f58f to your computer and use it in GitHub Desktop.
Rust experiments
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);
}
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