From 2b5c6ee675f7c8eebf05cb242e7b8328e15900e3 Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Mon, 23 Mar 2020 00:12:55 +0000 Subject: [PATCH] Removed unnecessary allocations within `StringError::with_err` and `StringError::with_err_backtrace`. --- src/constructor.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/constructor.rs b/src/constructor.rs index 0c161fd..95fe559 100644 --- a/src/constructor.rs +++ b/src/constructor.rs @@ -42,8 +42,11 @@ impl StringError /// Returns a function to be passed to `map_err`, `map_panic_err` or alike /// that returns a string error with the underlying error but no backtrace pub fn with_err>(msg: impl Into) -> impl FnOnce(R) -> Self { - let msg = msg.into(); - move |err| Self { msg, bt: (), err: err.into() } + move |err| Self { + msg: msg.into(), + bt: (), err: + err.into() + } } } @@ -53,8 +56,10 @@ impl StringError /// Returns a function to be passed to `map_err`, `map_panic_err` or alike /// that returns a string error with the underlying error and a backtrace pub fn with_err_backtrace>(msg: impl Into) -> impl FnOnce(R) -> Self { - let msg = msg.into(); - let bt = Backtrace::force_capture(); - move |err| Self { msg, bt, err: err.into() } + move |err| Self { + msg: msg.into(), + bt: Backtrace::force_capture(), + err: err.into() + } } }