From c5568b426cc5d05351e59b2d8fe6ef11c81b13be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Thu, 1 Aug 2019 19:19:31 -0500 Subject: [PATCH] Communicate better. update -> permit. Thanks @jonathandturner --- src/plugins/str.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/plugins/str.rs b/src/plugins/str.rs index b411b5bd..216b7019 100644 --- a/src/plugins/str.rs +++ b/src/plugins/str.rs @@ -41,10 +41,8 @@ impl Str { self.field = Some(field); } - fn update(&mut self) { - if self.action.is_some() { - self.log_error("can only apply one"); - } + fn permit(&mut self) -> bool { + self.action.is_none() } fn log_error(&mut self, message: &str) { @@ -52,18 +50,27 @@ impl Str { } fn for_to_int(&mut self) { - self.update(); - self.action = Some(Action::ToInteger); + if self.permit() { + self.action = Some(Action::ToInteger); + } else { + self.log_error("can only apply one"); + } } fn for_downcase(&mut self) { - self.update(); - self.action = Some(Action::Downcase); + if self.permit() { + self.action = Some(Action::Downcase); + } else { + self.log_error("can only apply one"); + } } fn for_upcase(&mut self) { - self.update(); - self.action = Some(Action::Upcase); + if self.permit() { + self.action = Some(Action::Upcase); + } else { + self.log_error("can only apply one"); + } } fn usage(&self) -> &'static str {