diff --git a/lib/etc/libimaginteraction/src/ask.rs b/lib/etc/libimaginteraction/src/ask.rs index 6b7b02c9..b8db14e7 100644 --- a/lib/etc/libimaginteraction/src/ask.rs +++ b/lib/etc/libimaginteraction/src/ask.rs @@ -57,8 +57,8 @@ fn ask_bool_(s: &str, default: Option, 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... } diff --git a/lib/etc/libimaginteraction/src/format.rs b/lib/etc/libimaginteraction/src/format.rs index 4073c61f..cb0d4779 100644 --- a/lib/etc/libimaginteraction/src/format.rs +++ b/lib/etc/libimaginteraction/src/format.rs @@ -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 { - 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::())?; Ok(()) } diff --git a/lib/etc/libimaginteraction/src/ui.rs b/lib/etc/libimaginteraction/src/ui.rs index 91d9f4e7..a6d77dc2 100644 --- a/lib/etc/libimaginteraction/src/ui.rs +++ b/lib/etc/libimaginteraction/src/ui.rs @@ -50,7 +50,7 @@ pub fn id_argument_long() -> &'static str { pub fn get_id(matches: &ArgMatches) -> Result> { 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| {