From f30158144507cb8c4761cce7f4e5f93cbcfd409b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 1 May 2022 16:56:32 +0200 Subject: [PATCH] feat(napi): make Error::from_reason() generic --- crates/napi/src/error.rs | 4 ++-- examples/napi-compat-mode/src/task.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/napi/src/error.rs b/crates/napi/src/error.rs index 8228cce8..c530e925 100644 --- a/crates/napi/src/error.rs +++ b/crates/napi/src/error.rs @@ -95,10 +95,10 @@ impl Error { } } - pub fn from_reason(reason: String) -> Self { + pub fn from_reason>(reason: T) -> Self { Error { status: Status::GenericFailure, - reason, + reason: reason.into(), #[cfg(all(feature = "tokio_rt", feature = "napi4"))] maybe_raw: ptr::null_mut(), } diff --git a/examples/napi-compat-mode/src/task.rs b/examples/napi-compat-mode/src/task.rs index 56d2352e..31b7ba79 100644 --- a/examples/napi-compat-mode/src/task.rs +++ b/examples/napi-compat-mode/src/task.rs @@ -58,7 +58,7 @@ impl Task for CountBufferLength { fn compute(&mut self) -> Result { if self.data.len() == 10 { - return Err(Error::from_reason("len can't be 5".to_string())); + return Err(Error::from_reason("len can't be 5")); } Ok(self.data.len()) }