ZTJ

.dev

by Zachery Jensen

Placeholder

Just a placeholder. This site is comically neglected. Someday I’ll fix that.

For now, here’s some random Rust code.

// Implicitly impl a trait for a type if it impls the trait's super traits via a blanket impl.

trait SayYes {
    fn say_yes(&self);
}

trait SayNo {
    fn say_no(&self);
}

trait SayYesAndNo: SayYes + SayNo {}

// Comment this line out and the code won't compile due to SuffixedSayer missing a SayYesAndNo impl.
impl<T> SayYesAndNo for T where T: SayYes + SayNo {}

struct SuffixedSayer {
    suffix: String,
}

impl SayYes for SuffixedSayer {
    fn say_yes(&self) {
        println!("Yes, {}", self.suffix);
    }
}

impl SayNo for SuffixedSayer {
    fn say_no(&self) {
        println!("No, {} ", self.suffix);
    }
}

fn induce_to_say<T: SayYesAndNo>(sayer: T) {
    sayer.say_yes();
    sayer.say_no();
}

fn main() {
    let sayer = SuffixedSayer {
        suffix: "Sir".to_string(),
    };

    induce_to_say(sayer);
}