[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)
} else if R_NO.is_match(&s[..]) {
return Ok(false)
} else if default.is_some() {
return Ok(default.unwrap())
} else if let Some(default) = default {
return Ok(default)
}
// else again...
}

View file

@ -97,7 +97,7 @@ impl HelperDef for ColorizeYellowHelper {
#[inline]
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())))?;
Ok(())
@ -108,7 +108,7 @@ pub struct 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> {
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();
out.write(&format!("{}", s.paint(p.value().render())))?;
Ok(())
@ -120,7 +120,7 @@ pub struct 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> {
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();
out.write(&format!("{}", s.paint(p.value().render())))?;
Ok(())
@ -132,7 +132,7 @@ pub struct 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> {
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();
out.write(&format!("{}", s.paint(p.value().render())))?;
Ok(())
@ -144,7 +144,7 @@ pub struct 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> {
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();
out.write(&format!("{}", s.paint(p.value().render())))?;
Ok(())
@ -152,8 +152,8 @@ impl HelperDef for StrikethroughHelper {
}
fn param_to_number(idx: usize, h: &Helper) -> Result<u64, RenderError> {
match h.param(idx).ok_or(RenderError::new("Too few arguments"))?.value() {
&Value::Number(ref num) => num.as_u64().ok_or_else(|| RenderError::new("Number cannot be parsed")),
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")),
_ => Err(RenderError::new("Type error: First argument should be a number")),
}
}
@ -164,7 +164,7 @@ pub struct 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> {
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);
out.write(&text)?;
Ok(())
@ -177,7 +177,7 @@ pub struct 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> {
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);
out.write(&text)?;
Ok(())
@ -190,7 +190,7 @@ pub struct 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> {
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>())?;
Ok(())
}

View file

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