Last active
August 29, 2015 14:01
-
-
Save bkerley/570b567d6d201306c794 to your computer and use it in GitHub Desktop.
i'm learning rust lol
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::mem::size_of; | |
struct Foo { | |
a: u32, | |
b: u32, | |
c: u32, | |
d: u32 | |
} | |
struct Bar { | |
a: Foo, | |
b: Foo, | |
c: Foo, | |
d: Foo | |
} | |
struct Baz { | |
a: Box<Bar>, | |
b: Box<Bar>, | |
c: Box<Bar>, | |
d: Box<Bar> | |
} | |
fn main() { | |
println!("a u32 is {} bytes", size_of::<u32>()); | |
println!("a Foo is {} bytes", size_of::<Foo>()); | |
println!("a Bar is {} bytes", size_of::<Bar>()); | |
println!("a Baz is {} bytes", size_of::<Baz>()); | |
} |
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
struct Inches(f64); | |
struct Centimeters(f64); | |
fn main() { | |
let i = Inches(12f64); | |
let c = inches_to_cm(i); | |
let Centimeters(c_actual) = c; | |
println!("12 inches is {} cm", c_actual); | |
} | |
fn inches_to_cm(Inches(i): (Inches)) -> Centimeters { | |
Centimeters(i * 30.0 / 12.0) | |
} |
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 main() { | |
println!("Hello world!"); | |
} |
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
enum List { | |
Cons(u32, Box<List>), | |
Nil | |
} | |
fn main() { | |
let list = Cons(1, box Cons(2, box Cons(3, box Nil))); | |
println!("this is a list {:?}", list); | |
} |
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 main() { | |
let mytup = (10, 20, 30.01); | |
println!("this is my tuple: {:?}", mytup); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment