Use is_empty

Check whether a collections is empty by using the `.is_empty` method
instead of comparing `.len()` to 0.
This commit is contained in:
Colin Benner 2018-11-21 19:15:35 +01:00 committed by Tiffany Bennett
parent 72864485b7
commit 612ca08306
6 changed files with 19 additions and 19 deletions

View file

@ -50,7 +50,7 @@ fn main() {
let mut i = 0;
let reply = eval(line);
for line in reply.lines() {
if line.trim().len() > 0 {
if !line.trim().is_empty() {
server.send(Command::NOTICE(reply_to.to_owned(), line.to_owned())).unwrap();
i += 1;
}

View file

@ -204,7 +204,7 @@ impl Context {
}))
}),
"log" => func!(fn log(num: Number, base: Number) {
if base.unit.len() > 0 {
if !base.unit.is_empty() {
Err("Base must be dimensionless".to_string())
} else {
Ok(Value::Number(Number {
@ -937,7 +937,7 @@ impl Context {
let mut cur_cat = None;
for (category, name) in out {
if category != cur_cat {
if cur.len() > 0 {
if !cur.is_empty() {
let cat_name = cur_cat.and_then(|x| self.category_names.get(x));
categories.push(UnitsInCategory {
category: cat_name.map(ToOwned::to_owned),
@ -948,7 +948,7 @@ impl Context {
}
cur.push(name.clone());
}
if cur.len() > 0 {
if !cur.is_empty() {
let cat_name = cur_cat.and_then(|x| self.category_names.get(x));
categories.push(UnitsInCategory {
category: cat_name.map(ToOwned::to_owned),

View file

@ -134,7 +134,7 @@ impl<'a> Iterator for TokenIterator<'a> {
_ => break
}
}
if buf.len() > 0 {
if !buf.is_empty() {
frac = Some(buf)
}
}
@ -159,7 +159,7 @@ impl<'a> Iterator for TokenIterator<'a> {
_ => break
}
}
if buf.len() > 0 {
if !buf.is_empty() {
exp = Some(buf)
}
}

View file

@ -235,7 +235,7 @@ impl NumberParts {
(None, None) => continue,
},
'u' => if let Some(unit) = self.raw_unit.as_ref() {
if unit.len() == 0 { continue }
if unit.is_empty() { continue }
let mut frac = vec![];
let mut toks = vec![];
@ -254,7 +254,7 @@ impl NumberParts {
}
}
}
if frac.len() > 0 {
if !frac.is_empty() {
toks.push("/".to_string());
if let Some(d) = self.divfactor.as_ref() {
toks.push(d.to_string());
@ -270,7 +270,7 @@ impl NumberParts {
}
write!(out, "{}", toks.join(" ")).unwrap();
} else if let Some(unit) = self.unit.as_ref() {
if unit.len() == 0 { continue }
if unit.is_empty() { continue }
if let Some(f) = self.factor.as_ref() {
write!(out, "* {} ", f).unwrap();
}
@ -279,7 +279,7 @@ impl NumberParts {
}
write!(out, "{}", unit).unwrap();
} else if let Some(dim) = self.dimensions.as_ref() {
if dim.len() == 0 { continue }
if dim.is_empty() { continue }
if let Some(f) = self.factor.as_ref() {
write!(out, "* {} ", f).unwrap();
}
@ -301,19 +301,19 @@ impl NumberParts {
continue
},
'd' => if let Some(dim) = self.dimensions.as_ref() {
if self.unit.is_none() || dim.len() == 0 { continue }
if self.unit.is_none() || dim.is_empty() { continue }
write!(out, "{}", dim).unwrap();
} else {
continue
},
'D' => if let Some(dim) = self.dimensions.as_ref() {
if dim.len() == 0 { continue }
if dim.is_empty() { continue }
write!(out, "{}", dim).unwrap();
} else {
continue
},
'p' => match (self.quantity.as_ref(), self.dimensions.as_ref().and_then(|x| {
if self.unit.is_some() && x.len() > 0 {
if self.unit.is_some() && !x.is_empty() {
Some(x)
} else {
None

View file

@ -154,7 +154,7 @@ impl<'a> Iterator for TokenIterator<'a> {
_ => break
}
}
if hex.len() == 0 {
if hex.is_empty() {
return Some(Token::Error(
"Malformed hexadecimal literal: No digits after 0x".to_owned()))
}
@ -175,7 +175,7 @@ impl<'a> Iterator for TokenIterator<'a> {
_ => break
}
}
if oct.len() == 0 {
if oct.is_empty() {
return Some(Token::Error(
"Malformed octal literal: No digits after 0o".to_owned()))
}
@ -196,7 +196,7 @@ impl<'a> Iterator for TokenIterator<'a> {
_ => break
}
}
if bin.len() == 0 {
if bin.is_empty() {
return Some(Token::Error(
"Malformed binary literal: No digits after 0b".to_owned()))
}
@ -237,7 +237,7 @@ impl<'a> Iterator for TokenIterator<'a> {
_ => break
}
}
if buf.len() == 0 {
if buf.is_empty() {
return Some(Token::Error(
"Malformed number literal: No digits after decimal point".to_owned()))
}
@ -270,7 +270,7 @@ impl<'a> Iterator for TokenIterator<'a> {
_ => break
}
}
if buf.len() == 0 {
if buf.is_empty() {
return Some(Token::Error(
"Malformed number literal: No digits after exponent".to_owned()))
}

View file

@ -66,7 +66,7 @@ fn root(rink: &Rink, req: &mut Request) -> IronResult<Response> {
_ => (),
};
if data.len() == 0 {
if data.is_empty() {
data.insert("main-page".to_owned(), true.to_json());
}