Deprecate NativeCallContext::new

This commit is contained in:
Stephen Chung 2021-11-28 12:41:33 +08:00
parent d88e17d177
commit c5317d7706
2 changed files with 30 additions and 20 deletions

View File

@ -13,12 +13,13 @@ Enhancements
------------ ------------
* Added `into_array` and `into_typed_array` for `Dynamic`. * Added `into_array` and `into_typed_array` for `Dynamic`.
* New `FnPtr::call` to simplify calling a function pointer. * Added `FnPtr::call` to simplify calling a function pointer.
Deprecated API's Deprecated API's
---------------- ----------------
* The internal `no_smartstring` feature is removed since `SmartString` now supports `no-std`. * The internal `no_smartstring` feature is removed since `SmartString` now supports `no-std`.
* `NativeCallContext::new` is deprecated because it is simpler to call a function pointer via `FnPtr::call`.
Version 1.2.1 Version 1.2.1

View File

@ -64,11 +64,11 @@ pub struct NativeCallContext<'a> {
pos: Position, pos: Position,
} }
impl<'a, M: AsRef<[&'a Module]> + ?Sized> impl<'a, M: AsRef<[&'a Module]> + ?Sized, S: AsRef<str> + 'a + ?Sized>
From<( From<(
&'a Engine, &'a Engine,
&'a str, &'a S,
Option<&'a str>, Option<&'a S>,
&'a Imports, &'a Imports,
&'a M, &'a M,
Position, Position,
@ -78,8 +78,8 @@ impl<'a, M: AsRef<[&'a Module]> + ?Sized>
fn from( fn from(
value: ( value: (
&'a Engine, &'a Engine,
&'a str, &'a S,
Option<&'a str>, Option<&'a S>,
&'a Imports, &'a Imports,
&'a M, &'a M,
Position, Position,
@ -87,8 +87,8 @@ impl<'a, M: AsRef<[&'a Module]> + ?Sized>
) -> Self { ) -> Self {
Self { Self {
engine: value.0, engine: value.0,
fn_name: value.1, fn_name: value.1.as_ref(),
source: value.2, source: value.2.map(|v| v.as_ref()),
mods: Some(value.3), mods: Some(value.3),
lib: value.4.as_ref(), lib: value.4.as_ref(),
pos: value.5, pos: value.5,
@ -96,14 +96,14 @@ impl<'a, M: AsRef<[&'a Module]> + ?Sized>
} }
} }
impl<'a, M: AsRef<[&'a Module]> + ?Sized> From<(&'a Engine, &'a str, &'a M)> impl<'a, M: AsRef<[&'a Module]> + ?Sized, S: AsRef<str> + 'a + ?Sized>
for NativeCallContext<'a> From<(&'a Engine, &'a S, &'a M)> for NativeCallContext<'a>
{ {
#[inline(always)] #[inline(always)]
fn from(value: (&'a Engine, &'a str, &'a M)) -> Self { fn from(value: (&'a Engine, &'a S, &'a M)) -> Self {
Self { Self {
engine: value.0, engine: value.0,
fn_name: value.1, fn_name: value.1.as_ref(),
source: None, source: None,
mods: None, mods: None,
lib: value.2.as_ref(), lib: value.2.as_ref(),
@ -113,13 +113,22 @@ impl<'a, M: AsRef<[&'a Module]> + ?Sized> From<(&'a Engine, &'a str, &'a M)>
} }
impl<'a> NativeCallContext<'a> { impl<'a> NativeCallContext<'a> {
/// Create a new [`NativeCallContext`]. /// _(internals)_ Create a new [`NativeCallContext`].
/// Exported under the `metadata` feature only.
#[deprecated(
since = "1.3.0",
note = "`NativeCallContext::new` will be moved under `internals`. Use `FnPtr::call` to call a function pointer directly."
)]
#[inline(always)] #[inline(always)]
#[must_use] #[must_use]
pub const fn new(engine: &'a Engine, fn_name: &'a str, lib: &'a [&Module]) -> Self { pub fn new(
engine: &'a Engine,
fn_name: &'a (impl AsRef<str> + 'a + ?Sized),
lib: &'a [&Module],
) -> Self {
Self { Self {
engine, engine,
fn_name, fn_name: fn_name.as_ref(),
source: None, source: None,
mods: None, mods: None,
lib, lib,
@ -134,18 +143,18 @@ impl<'a> NativeCallContext<'a> {
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
#[inline(always)] #[inline(always)]
#[must_use] #[must_use]
pub const fn new_with_all_fields( pub fn new_with_all_fields(
engine: &'a Engine, engine: &'a Engine,
fn_name: &'a str, fn_name: &'a (impl AsRef<str> + 'a + ?Sized),
source: Option<&'a str>, source: Option<&'a (impl AsRef<str> + 'a + ?Sized)>,
imports: &'a Imports, imports: &'a Imports,
lib: &'a [&Module], lib: &'a [&Module],
pos: Position, pos: Position,
) -> Self { ) -> Self {
Self { Self {
engine, engine,
fn_name, fn_name: fn_name.as_ref(),
source, source: source.map(|v| v.as_ref()),
mods: Some(imports), mods: Some(imports),
lib, lib,
pos, pos,