Skip to content

Instantly share code, notes, and snippets.

@kogai
Last active May 12, 2017 05:53
Show Gist options
  • Select an option

  • Save kogai/6e81085d0a1d4c8d4c46ff2c257e4c91 to your computer and use it in GitHub Desktop.

Select an option

Save kogai/6e81085d0a1d4c8d4c46ff2c257e4c91 to your computer and use it in GitHub Desktop.
RUSTFLAGS="--emit asm" cargo build
#![no_std]
pub trait Foo {
fn sum(&self, x: i32, y: i32) -> i32;
}
struct FooInstance;
impl Foo for FooInstance {
fn sum(&self, x: i32, y: i32) -> i32 {
x + y
}
}
struct FooInstance2;
impl Foo for FooInstance2 {
fn sum(&self, x: i32, y: i32) -> i32 {
x + y + 100
}
}
fn call_sum<T: Foo>(x: T) -> i32 {
x.sum(10, 10)
}
pub fn result() -> i32{
let f = FooInstance;
let f2 = FooInstance2;
call_sum(f) + call_sum(f2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment