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.
/// 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

View File

@ -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<T: Variant + Clone>(
&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<Shared<Module>>) -> &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<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.
///
/// # Example

View File

@ -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),

View File

@ -38,6 +38,16 @@ pub trait Package {
/// Retrieve the generic package library from this package.
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)