[No-auto] lib/etc/interaction: Fix Clippy warnings

Signed-off-by: flip1995 <hello@philkrones.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
flip1995 2019-08-27 10:19:15 +02:00 committed by Matthias Beyer
parent a8bb180a6a
commit 0087de7af8
3 changed files with 13 additions and 13 deletions

View file

@ -57,8 +57,8 @@ fn ask_bool_<R: BufRead>(s: &str, default: Option<bool>, input: &mut R, output:
return Ok(true) return Ok(true)
} else if R_NO.is_match(&s[..]) { } else if R_NO.is_match(&s[..]) {
return Ok(false) return Ok(false)
} else if default.is_some() { } else if let Some(default) = default {
return Ok(default.unwrap()) return Ok(default)
} }
// else again... // else again...
} }

View file

@ -97,7 +97,7 @@ impl HelperDef for ColorizeYellowHelper {
#[inline] #[inline]
fn colorize(color: Colour, h: &Helper, output: &mut dyn Output) -> Result<(), RenderError> { fn colorize(color: Colour, h: &Helper, output: &mut dyn Output) -> Result<(), RenderError> {
let p = h.param(0).ok_or(RenderError::new("Too few arguments"))?; let p = h.param(0).ok_or_else(|| RenderError::new("Too few arguments"))?;
output.write(&format!("{}", color.paint(p.value().render())))?; output.write(&format!("{}", color.paint(p.value().render())))?;
Ok(()) Ok(())
@ -108,7 +108,7 @@ pub struct UnderlineHelper;
impl HelperDef for UnderlineHelper { impl HelperDef for UnderlineHelper {
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> { fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> {
let p = h.param(0).ok_or(RenderError::new("Too few arguments"))?; let p = h.param(0).ok_or_else(|| RenderError::new("Too few arguments"))?;
let s = Style::new().underline(); let s = Style::new().underline();
out.write(&format!("{}", s.paint(p.value().render())))?; out.write(&format!("{}", s.paint(p.value().render())))?;
Ok(()) Ok(())
@ -120,7 +120,7 @@ pub struct BoldHelper;
impl HelperDef for BoldHelper { impl HelperDef for BoldHelper {
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> { fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> {
let p = h.param(0).ok_or(RenderError::new("Too few arguments"))?; let p = h.param(0).ok_or_else(|| RenderError::new("Too few arguments"))?;
let s = Style::new().bold(); let s = Style::new().bold();
out.write(&format!("{}", s.paint(p.value().render())))?; out.write(&format!("{}", s.paint(p.value().render())))?;
Ok(()) Ok(())
@ -132,7 +132,7 @@ pub struct BlinkHelper;
impl HelperDef for BlinkHelper { impl HelperDef for BlinkHelper {
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> { fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> {
let p = h.param(0).ok_or(RenderError::new("Too few arguments"))?; let p = h.param(0).ok_or_else(|| RenderError::new("Too few arguments"))?;
let s = Style::new().blink(); let s = Style::new().blink();
out.write(&format!("{}", s.paint(p.value().render())))?; out.write(&format!("{}", s.paint(p.value().render())))?;
Ok(()) Ok(())
@ -144,7 +144,7 @@ pub struct StrikethroughHelper;
impl HelperDef for StrikethroughHelper { impl HelperDef for StrikethroughHelper {
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> { fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> {
let p = h.param(0).ok_or(RenderError::new("Too few arguments"))?; let p = h.param(0).ok_or_else(|| RenderError::new("Too few arguments"))?;
let s = Style::new().strikethrough(); let s = Style::new().strikethrough();
out.write(&format!("{}", s.paint(p.value().render())))?; out.write(&format!("{}", s.paint(p.value().render())))?;
Ok(()) Ok(())
@ -152,8 +152,8 @@ impl HelperDef for StrikethroughHelper {
} }
fn param_to_number(idx: usize, h: &Helper) -> Result<u64, RenderError> { fn param_to_number(idx: usize, h: &Helper) -> Result<u64, RenderError> {
match h.param(idx).ok_or(RenderError::new("Too few arguments"))?.value() { match *h.param(idx).ok_or_else(|| RenderError::new("Too few arguments"))?.value() {
&Value::Number(ref num) => num.as_u64().ok_or_else(|| RenderError::new("Number cannot be parsed")), Value::Number(ref num) => num.as_u64().ok_or_else(|| RenderError::new("Number cannot be parsed")),
_ => Err(RenderError::new("Type error: First argument should be a number")), _ => Err(RenderError::new("Type error: First argument should be a number")),
} }
} }
@ -164,7 +164,7 @@ pub struct LeftPadHelper;
impl HelperDef for LeftPadHelper { impl HelperDef for LeftPadHelper {
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> { fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> {
let count = param_to_number(0, h)? as usize; let count = param_to_number(0, h)? as usize;
let text = h.param(1).ok_or(RenderError::new("Too few arguments"))?; let text = h.param(1).ok_or_else(|| RenderError::new("Too few arguments"))?;
let text = format!("{:>width$}", text.value().render(), width = count); let text = format!("{:>width$}", text.value().render(), width = count);
out.write(&text)?; out.write(&text)?;
Ok(()) Ok(())
@ -177,7 +177,7 @@ pub struct RightPadHelper;
impl HelperDef for RightPadHelper { impl HelperDef for RightPadHelper {
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> { fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> {
let count = param_to_number(0, h)? as usize; let count = param_to_number(0, h)? as usize;
let text = h.param(1).ok_or(RenderError::new("Too few arguments"))?; let text = h.param(1).ok_or_else(|| RenderError::new("Too few arguments"))?;
let text = format!("{:width$}", text.value().render(), width = count); let text = format!("{:width$}", text.value().render(), width = count);
out.write(&text)?; out.write(&text)?;
Ok(()) Ok(())
@ -190,7 +190,7 @@ pub struct AbbrevHelper;
impl HelperDef for AbbrevHelper { impl HelperDef for AbbrevHelper {
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> { fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Registry, _ctx: &'rc Context, _rc: &mut RenderContext<'reg>, out: &mut dyn Output) -> Result<(), RenderError> {
let count = param_to_number(0, h)? as usize; let count = param_to_number(0, h)? as usize;
let text = h.param(1).ok_or(RenderError::new("Too few arguments"))?.value().render(); let text = h.param(1).ok_or_else(|| RenderError::new("Too few arguments"))?.value().render();
out.write(&text.chars().take(count).collect::<String>())?; out.write(&text.chars().take(count).collect::<String>())?;
Ok(()) Ok(())
} }

View file

@ -50,7 +50,7 @@ pub fn id_argument_long() -> &'static str {
pub fn get_id(matches: &ArgMatches) -> Result<Vec<StoreId>> { pub fn get_id(matches: &ArgMatches) -> Result<Vec<StoreId>> {
matches matches
.values_of(id_argument_name()) .values_of(id_argument_name())
.ok_or(err_msg("CLI error")) .ok_or_else(|| err_msg("CLI error"))
.and_then(|vals| { .and_then(|vals| {
vals vals
.fold(Ok(vec![]), |acc, elem| { .fold(Ok(vec![]), |acc, elem| {