From b480c5709513d80764a62249ee239a72c8359ef5 Mon Sep 17 00:00:00 2001 From: Rock070 Date: Sat, 23 Dec 2023 11:38:04 +0800 Subject: [PATCH] Refactor is_international and get_fees methods in Package struct --- exercises/07_structs/structs3.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/exercises/07_structs/structs3.rs b/exercises/07_structs/structs3.rs index 7cda5af1..ae126861 100644 --- a/exercises/07_structs/structs3.rs +++ b/exercises/07_structs/structs3.rs @@ -7,7 +7,7 @@ // Execute `rustlings hint structs3` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE +// NOTE 結構體關聯函式與方法 #[derive(Debug)] struct Package { @@ -31,12 +31,14 @@ impl Package { } } - fn is_international(&self) -> ??? { + fn is_international(&self) -> bool { // Something goes here... + if self.sender_country == self.recipient_country { false } else { true } } - fn get_fees(&self, cents_per_gram: u32) -> ??? { + fn get_fees(&self, cents_per_gram: u32) -> u32 { // Something goes here... + self.weight_in_grams * cents_per_gram } }