Skip to content

Instantly share code, notes, and snippets.

@cgdangelo
Created May 7, 2018 22:54
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 cgdangelo/e699480c850d5868f0669276d376fec5 to your computer and use it in GitHub Desktop.
Save cgdangelo/e699480c850d5868f0669276d376fec5 to your computer and use it in GitHub Desktop.
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