Created
May 7, 2018 22:54
-
-
Save cgdangelo/e699480c850d5868f0669276d376fec5 to your computer and use it in GitHub Desktop.
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() { | |
use simfantasy::*; | |
let ss = StraightShot {}; | |
ss.perform(); | |
let hs = HeavyShot {}; | |
hs.perform(); | |
} | |
mod simfantasy { | |
pub trait Action { | |
fn name(&self) -> &str; | |
fn perform(&self); | |
} | |
pub struct StraightShot {} | |
impl Action for StraightShot { | |
fn name(&self) -> &str { "Straight Shot" } | |
fn perform(&self) { println!("Casted {} for some damage!", self.name()) } | |
} | |
pub struct HeavyShot {} | |
impl Action for HeavyShot { | |
fn name(&self) -> &str { "Heavy Shot" } | |
fn perform(&self) { println!("Casted {} for some damage!", self.name()) } | |
} | |
} | |
mod simfantasyii { | |
pub trait Action { | |
fn name(&self) -> &str; | |
} | |
pub trait PerformAction { | |
fn perform(&self); | |
} | |
impl<T> PerformAction for T where T: Action { | |
fn perform(&self) { println!("Casted {} for some damage!", self.name()) } | |
} | |
pub struct StraightShot {} | |
impl Action for StraightShot { | |
fn name(&self) -> &str { "Straight Shot" } | |
} | |
pub struct HeavyShot {} | |
impl Action for HeavyShot { | |
fn name(&self) -> &str { "Heavy Shot" } | |
} | |
} | |
mod simfantasyiii { | |
pub trait Action { | |
fn name(&self) -> &str; | |
fn perform(&self); | |
} | |
pub struct StraightShot {} | |
impl Action for StraightShot { | |
fn name(&self) -> &str { "Straight Shot" } | |
fn perform(&self) { perform_action(self) } | |
} | |
pub struct HeavyShot {} | |
impl Action for HeavyShot { | |
fn name(&self) -> &str { "Heavy Shot" } | |
fn perform(&self) { perform_action(self) } | |
} | |
fn perform_action(a: &Action) { println!("Casted {} for some damage!", a.name()) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment