From 019b1bb66d83bd904df3e545654f16e70e677ce8 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sun, 14 Jul 2019 09:58:48 -0700 Subject: Use FnMut over Fn in try_with_* and authenticate functions The try_with_* and authenticate functions accept a user-supplied function to work with. Currently this function is declared as Fn. That, however, is unnecessarily restrictive. With this change we declare said function an FnMut instead, which allows it to potentially capture variables from its environment in a mutable manner. --- nitrocli/src/commands.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index 583870b..f473db7 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -116,7 +116,7 @@ fn authenticate( ) -> Result where D: Device, - F: Fn(D, &str) -> result::Result, + F: FnMut(D, &str) -> result::Result, { let pin_entry = pinentry::PinEntry::from(pin_type, &device)?; @@ -183,10 +183,10 @@ fn try_with_pin_and_data_with_pinentry( pin_entry: &pinentry::PinEntry, msg: &'static str, data: D, - op: F, + mut op: F, ) -> Result where - F: Fn(D, &str) -> result::Result, + F: FnMut(D, &str) -> result::Result, { let mut data = data; let mut retry = 3; @@ -219,10 +219,10 @@ fn try_with_pin_and_data( pin_entry: &pinentry::PinEntry, msg: &'static str, data: D, - op: F, + mut op: F, ) -> Result where - F: Fn(D, &str) -> result::Result, + F: FnMut(D, &str) -> result::Result, { let pin = match pin_entry.pin_type() { pinentry::PinType::Admin => &ctx.admin_pin, @@ -250,10 +250,10 @@ fn try_with_pin( ctx: &mut args::ExecCtx<'_>, pin_entry: &pinentry::PinEntry, msg: &'static str, - op: F, + mut op: F, ) -> Result<()> where - F: Fn(&str) -> result::Result<(), nitrokey::CommandError>, + F: FnMut(&str) -> result::Result<(), nitrokey::CommandError>, { try_with_pin_and_data(ctx, pin_entry, msg, (), |data, pin| { op(pin).map_err(|err| (data, err)) -- cgit v1.2.1