1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-14 22:15:54 +02:00

Clarify constructors in the speaker notes for methods (#992)

This commit is contained in:
Dominik Maier 2023-07-17 23:17:26 +02:00 committed by GitHub
parent ba403016b9
commit e59a87f0c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,7 +31,7 @@ fn main() {
<details>
- Add a `Rectangle::new` constructor and call this from `main`:
- Add a static method called `Rectangle::new` and call this from `main`:
```rust,editable,compile_fail
fn new(width: u32, height: u32) -> Rectangle {
@ -39,7 +39,9 @@ fn main() {
}
```
- Add a `Rectangle::new_square(width: u32)` constructor to illustrate that
constructors can take arbitrary parameters.
- While _technically_, rust does not have custom constructors, static methods are commonly used to initialize structs (but don't have to).
The actual constructor, `Rectangle { width, height }`, could be called directly. See the [Rustnomicon](https://doc.rust-lang.org/nomicon/constructors.html).
- Add a `Rectangle::new_square(width: u32)` constructor to illustrate that such static methods can take arbitrary parameters.
</details>