feat(api) Avoid string allocations in FromToNativeWasmType.

When `from_native` or `to_native` fail, panic with a `&'static str`
instead of a `String`. Since this string is always created, it's
better to avoid this allocation for every call.
This commit is contained in:
Ivan Enderlin
2020-07-02 11:18:47 +02:00
parent 3f924dbb45
commit ea0a0ec127

View File

@@ -546,9 +546,8 @@ mod inner {
#[inline]
fn from_native(native: Self::Native) -> Self {
native.try_into().expect(&format!(
"cannot convert {}{} to {}",
native,
native.try_into().expect(concat!(
"out of range type conversion attempt (tried to convert `{}` to `{}`)",
stringify!($native_type),
stringify!($type),
))
@@ -556,9 +555,8 @@ mod inner {
#[inline]
fn to_native(self) -> Self::Native {
self.try_into().expect(&format!(
"cannot convert {}{} to {}",
self,
self.try_into().expect(concat!(
"out of range type conversion attempt (tried to convert `{}` to `{}`)",
stringify!($type),
stringify!($native_type),
))