From 1fa9dbc00e8d5eff8f698097afb112c142bb8da0 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 11 Feb 2017 10:00:56 -0800 Subject: [PATCH] Use functional transformations on the option instead of matching. --- src/librustdoc/clean/mod.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 4a6e862246010..751ed7d443d29 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -328,26 +328,23 @@ impl Item { } pub fn stability_class(&self) -> Option { - match self.stability { - Some(ref s) => { - let mut classes = Vec::with_capacity(2); + self.stability.as_ref().and_then(|ref s| { + let mut classes = Vec::with_capacity(2); - if s.level == stability::Unstable { - classes.push("unstable"); - } + if s.level == stability::Unstable { + classes.push("unstable"); + } - if !s.deprecated_since.is_empty() { - classes.push("deprecated"); - } + if !s.deprecated_since.is_empty() { + classes.push("deprecated"); + } - if classes.len() != 0 { - Some(classes.join(" ")) - } else { - None - } + if classes.len() != 0 { + Some(classes.join(" ")) + } else { + None } - None => None, - } + }) } pub fn stable_since(&self) -> Option<&str> {