In this post, I will give a very brief overview into Rust for developers who are already familiar with other languages such as Python, Java, C, etc…
Traits
A trait is the equivalent to an interface in Java.
struct Rectangle {height: i32, width: i32} // Test /// Block /// okay trait Shape{ fn surface(&self) -> i32; fn circumference(&self) -> i32; } impl Rectangle { fn setSize(height: i32, width: i32) { self.height = height; self.width = width; } } impl Shape for Rectangle { fn surface(&self) -> i32 { self.height*self.width } fn curcumference(&self) -> i32 { (self.height+self.width)*2 } }
2 Comments
Hi 大胡子🧔 congratulations!you will be good at sharing something with nice people new life start!😄🧚♀️
谢谢我最爱的开开😊