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()) }