Merge pull request #1159 from bnoordhuis/from_reason
feat(napi): make Error::from_reason() generic
This commit is contained in:
commit
a91a8b4201
2 changed files with 3 additions and 3 deletions
|
@ -95,10 +95,10 @@ impl Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_reason(reason: String) -> Self {
|
pub fn from_reason<T: Into<String>>(reason: T) -> Self {
|
||||||
Error {
|
Error {
|
||||||
status: Status::GenericFailure,
|
status: Status::GenericFailure,
|
||||||
reason,
|
reason: reason.into(),
|
||||||
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
|
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
|
||||||
maybe_raw: ptr::null_mut(),
|
maybe_raw: ptr::null_mut(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl Task for CountBufferLength {
|
||||||
|
|
||||||
fn compute(&mut self) -> Result<Self::Output> {
|
fn compute(&mut self) -> Result<Self::Output> {
|
||||||
if self.data.len() == 10 {
|
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())
|
Ok(self.data.len())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue