From d146de4ff987f23689e7940e16b82a447b3c7ee3 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 29 Jun 2021 21:47:27 +0800 Subject: [PATCH] Make FnPtr::fn_name_raw const. --- src/fn_call.rs | 4 ++-- src/fn_ptr.rs | 4 ++-- src/immutable_string.rs | 13 +++++++++++++ src/packages/fn_basic.rs | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/fn_call.rs b/src/fn_call.rs index cff7f146..36594362 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -951,7 +951,7 @@ impl Engine { fn_ptr.clone() } else { FnPtr::new_unchecked( - fn_ptr.get_fn_name().clone(), + fn_ptr.fn_name_raw().clone(), fn_ptr .curry() .iter() @@ -981,7 +981,7 @@ impl Engine { if let Some(val) = map.get(fn_name) { if let Some(fn_ptr) = val.read_lock::() { // Remap the function name - _redirected = fn_ptr.get_fn_name().clone(); + _redirected = fn_ptr.fn_name_raw().clone(); fn_name = &_redirected; // Add curried arguments if fn_ptr.is_curried() { diff --git a/src/fn_ptr.rs b/src/fn_ptr.rs index 77544d38..5c22208d 100644 --- a/src/fn_ptr.rs +++ b/src/fn_ptr.rs @@ -33,12 +33,12 @@ impl FnPtr { #[inline(always)] #[must_use] pub fn fn_name(&self) -> &str { - self.get_fn_name().as_ref() + self.fn_name_raw().as_ref() } /// Get the name of the function. #[inline(always)] #[must_use] - pub(crate) const fn get_fn_name(&self) -> &Identifier { + pub(crate) const fn fn_name_raw(&self) -> &Identifier { &self.0 } /// Get the underlying data of the function pointer. diff --git a/src/immutable_string.rs b/src/immutable_string.rs index 212ecc24..48c7e387 100644 --- a/src/immutable_string.rs +++ b/src/immutable_string.rs @@ -106,12 +106,25 @@ impl From for ImmutableString { } } #[cfg(not(feature = "no_smartstring"))] +impl From<&SmartString> for ImmutableString { + #[inline(always)] + fn from(value: &SmartString) -> Self { + Self(Into::::into(value.as_str()).into()) + } +} +#[cfg(not(feature = "no_smartstring"))] impl From for ImmutableString { #[inline(always)] fn from(value: SmartString) -> Self { Self(value.into()) } } +impl From<&ImmutableString> for SmartString { + #[inline(always)] + fn from(value: &ImmutableString) -> Self { + value.as_str().into() + } +} impl From for SmartString { #[inline(always)] fn from(mut value: ImmutableString) -> Self { diff --git a/src/packages/fn_basic.rs b/src/packages/fn_basic.rs index f88089c5..76e9d52d 100644 --- a/src/packages/fn_basic.rs +++ b/src/packages/fn_basic.rs @@ -11,7 +11,7 @@ def_package!(crate:BasicFnPackage:"Basic Fn functions.", lib, { mod fn_ptr_functions { #[rhai_fn(name = "name", get = "name", pure)] pub fn name(f: &mut FnPtr) -> ImmutableString { - f.get_fn_name().as_str().into() + f.fn_name_raw().into() } #[cfg(not(feature = "no_function"))]