lecture 3 stuff
This commit is contained in:
9 files changed
+400
No files matched your search
@@ -0,0 +1,15 @@
|
||||
// simple example of extension trait
|
||||
// how to add square method to i32
|
||||
trait Square {
|
||||
fn square(self) -> Self;
|
||||
}
|
||||
|
||||
impl Square for i32 {
|
||||
fn square(self) -> Self {
|
||||
self * self
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", 32.square());
|
||||
}
|
||||
Reference in new issue
Block a user