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 ???
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter