From 08e7ad8c0994e92a3fedb318e25609f76a98e1b2 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 23 Dec 2020 15:30:35 +0800 Subject: [PATCH] Add deprecated packages API. --- src/ast.rs | 4 ++-- src/engine_api.rs | 27 ++++++++++++++++++++++++++- src/lib.rs | 8 ++++---- src/packages/mod.rs | 10 ++++++++++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 9a207461..bc801376 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -228,7 +228,7 @@ impl AST { /// _(INTERNALS)_ Get the statements. /// Exported under the `internals` feature only. #[cfg(feature = "internals")] - #[deprecated(note = "this method is volatile and may change")] + #[deprecated = "this method is volatile and may change"] #[inline(always)] pub fn statements(&self) -> &[Stmt] { &self.statements @@ -255,7 +255,7 @@ impl AST { /// _(INTERNALS)_ Get the internal [`Module`] containing all script-defined functions. /// Exported under the `internals` feature only. #[cfg(feature = "internals")] - #[deprecated(note = "this method is volatile and may change")] + #[deprecated = "this method is volatile and may change"] #[inline(always)] pub fn lib(&self) -> &Module { &self.functions diff --git a/src/engine_api.rs b/src/engine_api.rs index 78164e29..0a38b820 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -48,7 +48,7 @@ impl Engine { /// Notice that this will _consume_ the argument, replacing it with `()`. /// /// 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)] pub fn register_raw_fn( &mut self, @@ -737,6 +737,16 @@ impl Engine { self.global_modules.insert(0, module); 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>) -> &mut Self { + self.register_global_module(module.into()) + } /// 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. @@ -776,6 +786,21 @@ impl Engine { } 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, + module: impl Into>, + ) -> &mut Self { + self.register_static_module(name, module.into()) + } /// Compile a string into an [`AST`], which can be used later for evaluation. /// /// # Example diff --git a/src/lib.rs b/src/lib.rs index 946fda30..00f60db2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,15 +174,15 @@ pub use optimize::OptimizationLevel; // Expose internal data structures. #[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}; #[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}; #[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}; #[cfg(feature = "internals")] @@ -190,7 +190,7 @@ pub use engine::{Imports, State as EvalState}; pub use engine::Limits; #[cfg(feature = "internals")] -#[deprecated(note = "this type is volatile and may change")] +#[deprecated = "this type is volatile and may change"] pub use module::NamespaceRef; /// _(INTERNALS)_ Alias to [`smallvec::SmallVec<[T; 4]>`](https://crates.io/crates/smallvec), diff --git a/src/packages/mod.rs b/src/packages/mod.rs index 89bb7fbb..9b7112bb 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -38,6 +38,16 @@ pub trait Package { /// Retrieve the generic package library from this package. fn as_shared_module(&self) -> Shared; + + /// Retrieve the generic package library from this package. + /// + /// ## Deprecated + /// + /// Use `as_shared_module` instead. + #[deprecated = "use `as_shared_module` instead"] + fn get(&self) -> Shared { + self.as_shared_module() + } } /// Macro that makes it easy to define a _package_ (which is basically a shared module)