Skip to content

Instantly share code, notes, and snippets.

@bkerley
Last active August 29, 2015 14:01
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 bkerley/570b567d6d201306c794 to your computer and use it in GitHub Desktop.
Save bkerley/570b567d6d201306c794 to your computer and use it in GitHub Desktop.
i'm learning rust lol
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>());
}
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)
}
fn main() {
println!("Hello world!");
}
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);
}
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