mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 12:39:42 +00:00
add zh/method
This commit is contained in:
@ -21,7 +21,7 @@
|
||||
- [Pattern Match](pattern-match/intro.md)
|
||||
- [match, matches! and if let](pattern-match/match-iflet.md)
|
||||
- [Patterns](pattern-match/patterns.md)
|
||||
- [Associated function & Method](method.md)
|
||||
- [Method & Associated function](method.md)
|
||||
- [Generics and Traits todo](generics-traits/intro.md)
|
||||
- [Generics](generics-traits/generics.md)
|
||||
- [Traits](generics-traits/traits.md)
|
||||
|
@ -193,7 +193,7 @@ struct TrafficLight {
|
||||
impl TrafficLight {
|
||||
// 1. implement a assotiated function `new`,
|
||||
// 2. it will return a TrafficLight contains color "red"
|
||||
// 3. must use `Self`, DONT use `TrafficLight`
|
||||
// 3. must use `Self`, DONT use `TrafficLight` in fn signatures or body
|
||||
pub fn new()
|
||||
|
||||
pub fn get_state(&self) -> &str {
|
||||
@ -216,7 +216,7 @@ struct Rectangle {
|
||||
height: u32,
|
||||
}
|
||||
|
||||
// rewrite Rectangle to use multiple `impl` blocks
|
||||
// using multiple `impl` blocks to rewrite the code below
|
||||
impl Rectangle {
|
||||
fn area(&self) -> u32 {
|
||||
self.width * self.height
|
||||
|
Reference in New Issue
Block a user