summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2019-08-27 10:19:15 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-08-28 18:18:41 +0200
commit0087de7af86f14d4cbb6696de7b3d38854410871 (patch)
tree706a151d965518f9245e67b5ca04d51f26b08f19
parenta8bb180a6a20b7b1dda7682b3fb5857e230ccb4c (diff)
[No-auto] lib/etc/interaction: Fix Clippy warnings
Signed-off-by: flip1995 <hello@philkrones.com> Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/etc/libimaginteraction/src/ask.rs4
-rw-r--r--lib/etc/libimaginteraction/src/format.rs20
-rw-r--r--lib/etc/libimaginteraction/src/ui.rs2
3 files changed, 13 insertions, 13 deletions
diff --git a/lib/etc/libimaginteraction/src/ask.rs b/lib/etc/libimaginteraction/src/ask.rs
index 6b7b02c..b8db14e 100644
--- a/lib/etc/libimaginteraction/src/ask.rs
+++ b/lib/etc/libimaginteraction/src/ask.rs
@@ -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...
}
diff --git a/lib/etc/libimaginteraction/src/format.rs b/lib/etc/libimaginteraction/src/format.rs
index 4073c61..cb0d477 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<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(())
}
diff --git a/lib/etc/libimaginteraction/src/ui.rs b/lib/etc/libimaginteraction/src/ui.rs
index 91d9f4e..a6d77dc 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<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| {