Add deprecated packages API.

This commit is contained in:
Stephen Chung 2020-12-23 15:30:35 +08:00
parent 746a0b186f
commit 08e7ad8c09
4 changed files with 42 additions and 7 deletions

View File

@ -228,7 +228,7 @@ impl AST {
/// _(INTERNALS)_ Get the statements. /// _(INTERNALS)_ Get the statements.
/// Exported under the `internals` feature only. /// Exported under the `internals` feature only.
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated(note = "this method is volatile and may change")] #[deprecated = "this method is volatile and may change"]
#[inline(always)] #[inline(always)]
pub fn statements(&self) -> &[Stmt] { pub fn statements(&self) -> &[Stmt] {
&self.statements &self.statements
@ -255,7 +255,7 @@ impl AST {
/// _(INTERNALS)_ Get the internal [`Module`] containing all script-defined functions. /// _(INTERNALS)_ Get the internal [`Module`] containing all script-defined functions.
/// Exported under the `internals` feature only. /// Exported under the `internals` feature only.
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated(note = "this method is volatile and may change")] #[deprecated = "this method is volatile and may change"]
#[inline(always)] #[inline(always)]
pub fn lib(&self) -> &Module { pub fn lib(&self) -> &Module {
&self.functions &self.functions

View File

@ -48,7 +48,7 @@ impl Engine {
/// Notice that this will _consume_ the argument, replacing it with `()`. /// Notice that this will _consume_ the argument, replacing it with `()`.
/// ///
/// To access the first mutable parameter, use `args.get_mut(0).unwrap()` /// To access the first mutable parameter, use `args.get_mut(0).unwrap()`
#[deprecated(note = "this function is volatile and may change")] #[deprecated = "this function is volatile and may change"]
#[inline(always)] #[inline(always)]
pub fn register_raw_fn<T: Variant + Clone>( pub fn register_raw_fn<T: Variant + Clone>(
&mut self, &mut self,
@ -737,6 +737,16 @@ impl Engine {
self.global_modules.insert(0, module); self.global_modules.insert(0, module);
self self
} }
/// Register a shared [`Module`][crate::Module] into the global namespace of [`Engine`].
///
/// ## Deprecated
///
/// Use `register_global_module` instead.
#[inline(always)]
#[deprecated = "use `register_global_module` instead"]
pub fn load_package(&mut self, module: impl Into<Shared<Module>>) -> &mut Self {
self.register_global_module(module.into())
}
/// Register a shared [`Module`][crate::Module] as a static module namespace with the [`Engine`]. /// Register a shared [`Module`][crate::Module] as a static module namespace with the [`Engine`].
/// ///
/// Functions marked `FnNamespace::Global` and type iterators are exposed to scripts without namespace qualifications. /// Functions marked `FnNamespace::Global` and type iterators are exposed to scripts without namespace qualifications.
@ -776,6 +786,21 @@ impl Engine {
} }
self self
} }
/// Register a shared [`Module`][crate::Module] as a static module namespace with the [`Engine`].
///
/// ## Deprecated
///
/// Use `register_static_module` instead.
#[cfg(not(feature = "no_module"))]
#[inline(always)]
#[deprecated = "use `register_static_module` instead"]
pub fn register_module(
&mut self,
name: impl Into<crate::ImmutableString>,
module: impl Into<Shared<Module>>,
) -> &mut Self {
self.register_static_module(name, module.into())
}
/// Compile a string into an [`AST`], which can be used later for evaluation. /// Compile a string into an [`AST`], which can be used later for evaluation.
/// ///
/// # Example /// # Example

View File

@ -174,15 +174,15 @@ pub use optimize::OptimizationLevel;
// Expose internal data structures. // Expose internal data structures.
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated(note = "this type is volatile and may change")] #[deprecated = "this type is volatile and may change"]
pub use token::{get_next_token, parse_string_literal, InputStream, Token, TokenizeState}; pub use token::{get_next_token, parse_string_literal, InputStream, Token, TokenizeState};
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated(note = "this type is volatile and may change")] #[deprecated = "this type is volatile and may change"]
pub use ast::{BinaryExpr, CustomExpr, Expr, FnCallExpr, Ident, ReturnType, ScriptFnDef, Stmt}; pub use ast::{BinaryExpr, CustomExpr, Expr, FnCallExpr, Ident, ReturnType, ScriptFnDef, Stmt};
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated(note = "this type is volatile and may change")] #[deprecated = "this type is volatile and may change"]
pub use engine::{Imports, State as EvalState}; pub use engine::{Imports, State as EvalState};
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
@ -190,7 +190,7 @@ pub use engine::{Imports, State as EvalState};
pub use engine::Limits; pub use engine::Limits;
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated(note = "this type is volatile and may change")] #[deprecated = "this type is volatile and may change"]
pub use module::NamespaceRef; pub use module::NamespaceRef;
/// _(INTERNALS)_ Alias to [`smallvec::SmallVec<[T; 4]>`](https://crates.io/crates/smallvec), /// _(INTERNALS)_ Alias to [`smallvec::SmallVec<[T; 4]>`](https://crates.io/crates/smallvec),

View File

@ -38,6 +38,16 @@ pub trait Package {
/// Retrieve the generic package library from this package. /// Retrieve the generic package library from this package.
fn as_shared_module(&self) -> Shared<Module>; fn as_shared_module(&self) -> Shared<Module>;
/// Retrieve the generic package library from this package.
///
/// ## Deprecated
///
/// Use `as_shared_module` instead.
#[deprecated = "use `as_shared_module` instead"]
fn get(&self) -> Shared<Module> {
self.as_shared_module()
}
} }
/// Macro that makes it easy to define a _package_ (which is basically a shared module) /// Macro that makes it easy to define a _package_ (which is basically a shared module)