From 31c3df1ff1633fd408319c14ff87d79f29515b20 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 12 Nov 2020 00:22:15 +0000 Subject: [PATCH] wip thunk etc. Signed-off-by: Ian Jackson --- src/bin/otter.rs | 7 ++++--- src/utils.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 5efb3208..57e42f2f 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -128,7 +128,8 @@ fn parse_args( mem::drop(ap); let completed = completer(parsed).unwrap_or_else(|e:ArgumentParseError| { - let ap = apmaker(&mut default()); + let mut def = default(); + let ap = apmaker(&mut def); ap.error(&us, &e.0, &mut stderr); exit(EXIT_USAGE); }); @@ -197,10 +198,10 @@ fn main() { let config = Thunk::new(||{ ServerConfig::read(config_filename.as_ref().map(String::as_str)) .context("read config file")?; - Ok(otter::global::config()) + Ok::<_,AE>(otter::global::config()) }); let socket_path = socket_path.map(Ok::<_,APE>).unwrap_or_else(||{ - Ok(config?.command_socket.clone()) + Ok((*config)?.command_socket.clone()) })?; Ok((subcommand, subargs, MainOpts { account, diff --git a/src/utils.rs b/src/utils.rs index 87a98572..26196c2f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -92,4 +92,12 @@ impl T> Deref for Thunk { } } +impl Result> + From, F>> for Result +{ + fn from(thunk: Thunk, F>) -> Result { + Thunk::into_inner(thunk) + } +} + // todo: DerefMut -- 2.30.2