mirror of
https://github.com/Zenithsiz/string-err.git
synced 2026-02-03 08:12:26 +00:00
Removed unnecessary allocations within StringError::with_err and StringError::with_err_backtrace.
This commit is contained in:
parent
0d4311ab61
commit
2b5c6ee675
@ -42,8 +42,11 @@ impl<E: Sized> StringError<E, ()>
|
|||||||
/// Returns a function to be passed to `map_err`, `map_panic_err` or alike
|
/// 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
|
/// that returns a string error with the underlying error but no backtrace
|
||||||
pub fn with_err<R: Into<E>>(msg: impl Into<String>) -> impl FnOnce(R) -> Self {
|
pub fn with_err<R: Into<E>>(msg: impl Into<String>) -> impl FnOnce(R) -> Self {
|
||||||
let msg = msg.into();
|
move |err| Self {
|
||||||
move |err| Self { msg, bt: (), err: err.into() }
|
msg: msg.into(),
|
||||||
|
bt: (), err:
|
||||||
|
err.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,8 +56,10 @@ impl<E: Sized> StringError<E, Backtrace>
|
|||||||
/// Returns a function to be passed to `map_err`, `map_panic_err` or alike
|
/// 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
|
/// that returns a string error with the underlying error and a backtrace
|
||||||
pub fn with_err_backtrace<R: Into<E>>(msg: impl Into<String>) -> impl FnOnce(R) -> Self {
|
pub fn with_err_backtrace<R: Into<E>>(msg: impl Into<String>) -> impl FnOnce(R) -> Self {
|
||||||
let msg = msg.into();
|
move |err| Self {
|
||||||
let bt = Backtrace::force_capture();
|
msg: msg.into(),
|
||||||
move |err| Self { msg, bt, err: err.into() }
|
bt: Backtrace::force_capture(),
|
||||||
|
err: err.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user