Update Ch15

This commit is contained in:
Unisko PENG
2023-05-11 14:30:55 +08:00
parent 5d41b08015
commit 5b4c6d8b1a
3 changed files with 47 additions and 10 deletions

View File

@@ -25,14 +25,11 @@ where
let percentage_of_max = self.value as f64 / self.max as f64;
if percentage_of_max >= 1.0 {
self.messenger.send("出错:你已超出你的配额!");
} else if percentage_of_max >= 0.9 {
self.messenger
.send("紧急警告:你已用掉你配额的 90% ");
} else if percentage_of_max >= 0.75 {
self.messenger
.send("警告:你已用掉你配额的 75% ");
match percentage_of_max {
max if max >= 1.0 => self.messenger.send("出错:你已超出你的配额!"),
max if max >= 0.9 => self.messenger.send("紧急警告:你已用掉你配额的 90% "),
max if max >= 0.75 => self.messenger.send("警告:你已用掉你配额的 75% "),
_ => {},
}
}
}

View File

@@ -10,8 +10,17 @@ fn main() {
id: id_variable @ 3..=7,
} => println! ("找到位于范围内的一个 id: {}", id_variable),
Message::Hello { id: 10..=12 } => {
println! ("找到位于另一范围的一个 {}", id);
println! ("找到位于另一范围的一个 id");
},
Message::Hello { id } => println! ("找到别的一个 id: {}", id),
}
let level = 0.8;
match level {
l if l >= 1.0 => println! ("超出额度"),
l if l >= 0.9 => println! ("超出 90% 额度"),
l if l >= 0.75 => println! ("超出 75% 额度"),
_ => (),
}
}