diff options
author | Daniel Mueller <deso@posteo.net> | 2019-07-14 09:58:48 -0700 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-07-14 09:58:48 -0700 |
commit | 019b1bb66d83bd904df3e545654f16e70e677ce8 (patch) | |
tree | f6e0e397214ec0d3f13d21faa0ba722c8205cb7c | |
parent | 1d62e9151369ab50d98d638e80753630c0c3cbbf (diff) | |
download | nitrocli-019b1bb66d83bd904df3e545654f16e70e677ce8.tar.gz nitrocli-019b1bb66d83bd904df3e545654f16e70e677ce8.tar.bz2 |
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.
-rw-r--r-- | nitrocli/src/commands.rs | 14 |
1 files 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<D, A, F>( ) -> Result<A> where D: Device, - F: Fn(D, &str) -> result::Result<A, (D, nitrokey::CommandError)>, + F: FnMut(D, &str) -> result::Result<A, (D, nitrokey::CommandError)>, { let pin_entry = pinentry::PinEntry::from(pin_type, &device)?; @@ -183,10 +183,10 @@ fn try_with_pin_and_data_with_pinentry<D, F, R>( pin_entry: &pinentry::PinEntry, msg: &'static str, data: D, - op: F, + mut op: F, ) -> Result<R> where - F: Fn(D, &str) -> result::Result<R, (D, nitrokey::CommandError)>, + F: FnMut(D, &str) -> result::Result<R, (D, nitrokey::CommandError)>, { let mut data = data; let mut retry = 3; @@ -219,10 +219,10 @@ fn try_with_pin_and_data<D, F, R>( pin_entry: &pinentry::PinEntry, msg: &'static str, data: D, - op: F, + mut op: F, ) -> Result<R> where - F: Fn(D, &str) -> result::Result<R, (D, nitrokey::CommandError)>, + F: FnMut(D, &str) -> result::Result<R, (D, nitrokey::CommandError)>, { let pin = match pin_entry.pin_type() { pinentry::PinType::Admin => &ctx.admin_pin, @@ -250,10 +250,10 @@ fn try_with_pin<F>( 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)) |