diff --git a/src/basic-syntax/methods.md b/src/basic-syntax/methods.md index d11d2946..5294d88d 100644 --- a/src/basic-syntax/methods.md +++ b/src/basic-syntax/methods.md @@ -1,7 +1,7 @@ # Methods -Rust has methods, they are simply functions that are associated with a particular type. The -first argument of a method is an instance of the type it is associated with: +Methods are functions associated with a type. The `self` argument of a method is +an instance of the type it is associated with: ```rust,editable struct Rectangle { @@ -28,3 +28,18 @@ fn main() { ``` * We will look much more at methods in today's exercise and in tomorrow's class. + +<details> + +- Add a `Rectangle::new` constructor and call this from `main`: + + ```rust,editable,compile_fail + fn new(width: u32, height: u32) -> Rectangle { + Rectangle { width, height } + } + ``` + +- Add a `Rectangle::new_square(width: u32)` constructor to illustrate that + constructors can take arbitrary parameters. + +</details>