Trait

PHOTO EMBED

Fri Jul 22 2022 01:44:36 GMT+0000 (Coordinated Universal Time)

Saved by @Polly #struct

struct MyStruct {
  isHappy: bool
}

trait Noisy {
  fn get_noise(&self) -> &str
}

impl Noisy for MyStruct {
  fn get_noise(&self) -> &str { "Meow?" }
}

****** DEFAULT TRAIT IMPL
trait Run {
  // no properties - use setter,getter
  fun run(&self) {
    // exe
  }
}
struct Robot {}
impl Run for Robot {}

fn main() {
  let robot = Robot {};
  robot.run();
}


Robot::Run::run() ??? this works ???

content_copyCOPY

https://www.udemy.com/course/ultimate-rust-crash-course/learn/lecture/17981939#overview