Skip to content

Instantly share code, notes, and snippets.

@pjhades
Created February 27, 2018 20:00
Show Gist options
  • Save pjhades/c71995718c15d385cf507adae9aa88e3 to your computer and use it in GitHub Desktop.
Save pjhades/c71995718c15d385cf507adae9aa88e3 to your computer and use it in GitHub Desktop.
struct S;
impl S {
fn foo(&self) { println!("S::foo"); }
fn bar(&self) { println!("S::bar"); }
}
fn foo() { println!("foo"); }
fn bar() { println!("bar"); }
fn main() {
let fps: [fn();2] = [foo, bar];
for f in fps.iter() {
f();
}
println!("sizeof={}", std::mem::size_of_val(&fps));
let s = S {};
let fps: [&Fn(&S);2] = [&S::foo, &S::bar];
for f in fps.iter() {
f(&s);
}
println!("sizeof={}", std::mem::size_of_val(&fps));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment