clippy lint: avoid manual implementation of Option

This commit is contained in:
auronandace 2021-08-22 08:08:11 +01:00 committed by Abin Simon
parent 74fbb96e68
commit e738de7b8c
7 changed files with 12 additions and 35 deletions

View file

@ -84,11 +84,8 @@ impl Configurable<Self> for ColorOption {
return Some(Self::Never); return Some(Self::Never);
} }
if let Some(color) = &config.color { config.color.as_ref()
Some(color.when) .map(|color| color.when)
} else {
None
}
} }
fn from_environment() -> Option<Self> { fn from_environment() -> Option<Self> {

View file

@ -29,11 +29,8 @@ impl Configurable<Self> for Dereference {
/// If the `Config::dereference` has value, this returns its value /// If the `Config::dereference` has value, this returns its value
/// as the value of the `Dereference`, in a [Some], Otherwise this returns [None]. /// as the value of the `Dereference`, in a [Some], Otherwise this returns [None].
fn from_config(config: &Config) -> Option<Self> { fn from_config(config: &Config) -> Option<Self> {
if let Some(deref) = &config.dereference { config.dereference.as_ref()
Some(Self(*deref)) .map(|deref| Self(*deref))
} else {
None
}
} }
} }

View file

@ -30,11 +30,8 @@ impl Configurable<Self> for Indicators {
/// this returns its value as the value of the `Indicators`, in a [Some]. /// this returns its value as the value of the `Indicators`, in a [Some].
/// Otherwise this returns [None]. /// Otherwise this returns [None].
fn from_config(config: &Config) -> Option<Self> { fn from_config(config: &Config) -> Option<Self> {
if let Some(ind) = &config.indicators { config.indicators.as_ref()
Some(Self(*ind)) .map(|ind| Self(*ind))
} else {
None
}
} }
} }

View file

@ -21,11 +21,8 @@ impl Configurable<Self> for SymlinkArrow {
/// returns its value as the value of the `SymlinkArrow`, in a [Some]. /// returns its value as the value of the `SymlinkArrow`, in a [Some].
/// Otherwise this returns [None]. /// Otherwise this returns [None].
fn from_config(config: &Config) -> Option<Self> { fn from_config(config: &Config) -> Option<Self> {
if let Some(arrow) = &config.symlink_arrow { config.symlink_arrow.as_ref()
Some(SymlinkArrow(arrow.to_string())) .map(|arrow| SymlinkArrow(arrow.to_string()))
} else {
None
}
} }
} }

View file

@ -30,11 +30,7 @@ impl Configurable<Self> for NoSymlink {
/// this returns it as the value of the `NoSymlink`, in a [Some]. /// this returns it as the value of the `NoSymlink`, in a [Some].
/// Otherwise this returns [None]. /// Otherwise this returns [None].
fn from_config(config: &Config) -> Option<Self> { fn from_config(config: &Config) -> Option<Self> {
if let Some(no_link) = config.no_symlink { config.no_symlink.map(Self)
Some(Self(no_link))
} else {
None
}
} }
} }

View file

@ -30,11 +30,7 @@ impl Configurable<Self> for TotalSize {
/// this returns it as the value of the `TotalSize`, in a [Some]. /// this returns it as the value of the `TotalSize`, in a [Some].
/// Otherwise this returns [None]. /// Otherwise this returns [None].
fn from_config(config: &Config) -> Option<Self> { fn from_config(config: &Config) -> Option<Self> {
if let Some(total) = config.total_size { config.total_size.map(Self)
Some(Self(total))
} else {
None
}
} }
} }

View file

@ -45,11 +45,8 @@ impl<'a> From<&'a Path> for SymLink {
impl SymLink { impl SymLink {
pub fn symlink_string(&self) -> Option<String> { pub fn symlink_string(&self) -> Option<String> {
if let Some(ref target) = self.target { self.target.as_ref()
Some(target.to_string()) .map(|target| target.to_string())
} else {
None
}
} }
pub fn render(&self, colors: &Colors, flag: &Flags) -> ColoredString { pub fn render(&self, colors: &Colors, flag: &Flags) -> ColoredString {