mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-24 04:59:41 +00:00
add zh/method
This commit is contained in:
@ -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