Use #[inline(always)] only when relatively certain.
This commit is contained in:
parent
313999b0ac
commit
9c16d90de9
12
src/ast.rs
12
src/ast.rs
@ -718,7 +718,7 @@ impl AST {
|
|||||||
/// Not available under `no_function`.
|
/// Not available under `no_function`.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn iter_fn_def(&self) -> impl Iterator<Item = &ScriptFnDef> {
|
pub(crate) fn iter_fn_def(&self) -> impl Iterator<Item = &ScriptFnDef> {
|
||||||
self.functions
|
self.functions
|
||||||
.iter_script_fn()
|
.iter_script_fn()
|
||||||
@ -728,7 +728,7 @@ impl AST {
|
|||||||
///
|
///
|
||||||
/// Not available under `no_function`.
|
/// Not available under `no_function`.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter_functions<'a>(&'a self) -> impl Iterator<Item = ScriptFnMetadata> + 'a {
|
pub fn iter_functions<'a>(&'a self) -> impl Iterator<Item = ScriptFnMetadata> + 'a {
|
||||||
self.functions
|
self.functions
|
||||||
.iter_script_fn()
|
.iter_script_fn()
|
||||||
@ -944,7 +944,7 @@ impl fmt::Debug for StmtBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<StmtBlock> for Stmt {
|
impl From<StmtBlock> for Stmt {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from(block: StmtBlock) -> Self {
|
fn from(block: StmtBlock) -> Self {
|
||||||
let block_pos = block.position();
|
let block_pos = block.position();
|
||||||
Self::Block(block.0.into_boxed_slice(), block_pos)
|
Self::Block(block.0.into_boxed_slice(), block_pos)
|
||||||
@ -1852,7 +1852,7 @@ impl<F: Float> From<F> for FloatWrapper<F> {
|
|||||||
impl<F: Float + FromStr> FromStr for FloatWrapper<F> {
|
impl<F: Float + FromStr> FromStr for FloatWrapper<F> {
|
||||||
type Err = <F as FromStr>::Err;
|
type Err = <F as FromStr>::Err;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
F::from_str(s).map(Into::<Self>::into)
|
F::from_str(s).map(Into::<Self>::into)
|
||||||
}
|
}
|
||||||
@ -2132,7 +2132,7 @@ impl Expr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is the expression a simple variable access?
|
/// Is the expression a simple variable access?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) const fn is_variable_access(&self, non_qualified: bool) -> bool {
|
pub(crate) const fn is_variable_access(&self, non_qualified: bool) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -2141,7 +2141,7 @@ impl Expr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Return the variable name if the expression a simple variable access.
|
/// Return the variable name if the expression a simple variable access.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn get_variable_name(&self, non_qualified: bool) -> Option<&str> {
|
pub(crate) fn get_variable_name(&self, non_qualified: bool) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
|
@ -255,7 +255,7 @@ enum DynamicReadLockInner<'d, T: Clone> {
|
|||||||
impl<'d, T: Any + Clone> Deref for DynamicReadLock<'d, T> {
|
impl<'d, T: Any + Clone> Deref for DynamicReadLock<'d, T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
DynamicReadLockInner::Reference(ref reference) => *reference,
|
DynamicReadLockInner::Reference(ref reference) => *reference,
|
||||||
@ -296,7 +296,7 @@ enum DynamicWriteLockInner<'d, T: Clone> {
|
|||||||
impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
|
impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
DynamicWriteLockInner::Reference(ref reference) => *reference,
|
DynamicWriteLockInner::Reference(ref reference) => *reference,
|
||||||
@ -307,7 +307,7 @@ impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Any + Clone> DerefMut for DynamicWriteLock<'d, T> {
|
impl<'d, T: Any + Clone> DerefMut for DynamicWriteLock<'d, T> {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
DynamicWriteLockInner::Reference(ref mut reference) => *reference,
|
DynamicWriteLockInner::Reference(ref mut reference) => *reference,
|
||||||
@ -384,17 +384,16 @@ impl Dynamic {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_shared(&self) -> bool {
|
pub const fn is_shared(&self) -> bool {
|
||||||
match self.0 {
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(_, _, _) => true,
|
return matches!(self.0, Union::Shared(_, _, _));
|
||||||
_ => false,
|
#[cfg(feature = "no_closure")]
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
/// Is the value held by this [`Dynamic`] a particular type?
|
/// Is the value held by this [`Dynamic`] a particular type?
|
||||||
///
|
///
|
||||||
/// If the [`Dynamic`] is a shared variant checking is performed on
|
/// If the [`Dynamic`] is a shared variant checking is performed on
|
||||||
/// top of its internal value.
|
/// top of its internal value.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is<T: Any + Clone>(&self) -> bool {
|
pub fn is<T: Any + Clone>(&self) -> bool {
|
||||||
if TypeId::of::<T>() == TypeId::of::<String>() {
|
if TypeId::of::<T>() == TypeId::of::<String>() {
|
||||||
@ -1221,7 +1220,7 @@ impl Dynamic {
|
|||||||
///
|
///
|
||||||
/// If the [`Dynamic`] value is already shared, this method returns itself.
|
/// If the [`Dynamic`] value is already shared, this method returns itself.
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn into_shared(self) -> Self {
|
pub fn into_shared(self) -> Self {
|
||||||
let _access = self.access_mode();
|
let _access = self.access_mode();
|
||||||
@ -1452,7 +1451,7 @@ impl Dynamic {
|
|||||||
/// If the [`Dynamic`] is not a shared value, it returns a cloned copy.
|
/// If the [`Dynamic`] is not a shared value, it returns a cloned copy.
|
||||||
///
|
///
|
||||||
/// If the [`Dynamic`] is a shared value, it returns a cloned copy of the shared value.
|
/// If the [`Dynamic`] is a shared value, it returns a cloned copy of the shared value.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn flatten_clone(&self) -> Self {
|
pub fn flatten_clone(&self) -> Self {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
@ -1471,7 +1470,7 @@ impl Dynamic {
|
|||||||
///
|
///
|
||||||
/// If the [`Dynamic`] is a shared value, it returns the shared value if there are no
|
/// If the [`Dynamic`] is a shared value, it returns the shared value if there are no
|
||||||
/// outstanding references, or a cloned copy.
|
/// outstanding references, or a cloned copy.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn flatten(self) -> Self {
|
pub fn flatten(self) -> Self {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
@ -1495,7 +1494,7 @@ impl Dynamic {
|
|||||||
///
|
///
|
||||||
/// If the [`Dynamic`] is a shared value, it is set to the shared value if there are no
|
/// If the [`Dynamic`] is a shared value, it is set to the shared value if there are no
|
||||||
/// outstanding references, or a cloned copy otherwise.
|
/// outstanding references, or a cloned copy otherwise.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn flatten_in_place(&mut self) -> &mut Self {
|
pub(crate) fn flatten_in_place(&mut self) -> &mut Self {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
@ -1528,7 +1527,7 @@ impl Dynamic {
|
|||||||
/// Access just waits until the [`RwLock`][std::sync::RwLock] is released.
|
/// Access just waits until the [`RwLock`][std::sync::RwLock] is released.
|
||||||
/// So this method always returns [`false`] under [`Sync`].
|
/// So this method always returns [`false`] under [`Sync`].
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_locked(&self) -> bool {
|
pub fn is_locked(&self) -> bool {
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
@ -1895,7 +1894,7 @@ impl Dynamic {
|
|||||||
/// Convert the [`Dynamic`] into a [`String`] and return it.
|
/// Convert the [`Dynamic`] into a [`String`] and return it.
|
||||||
/// If there are other references to the same string, a cloned copy is returned.
|
/// If there are other references to the same string, a cloned copy is returned.
|
||||||
/// Returns the name of the actual type if the cast fails.
|
/// Returns the name of the actual type if the cast fails.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn into_string(self) -> Result<String, &'static str> {
|
pub fn into_string(self) -> Result<String, &'static str> {
|
||||||
self.into_immutable_string()
|
self.into_immutable_string()
|
||||||
.map(ImmutableString::into_owned)
|
.map(ImmutableString::into_owned)
|
||||||
@ -1997,7 +1996,7 @@ impl Dynamic {
|
|||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
impl<T: Variant + Clone> From<Vec<T>> for Dynamic {
|
impl<T: Variant + Clone> From<Vec<T>> for Dynamic {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from(value: Vec<T>) -> Self {
|
fn from(value: Vec<T>) -> Self {
|
||||||
Self(Union::Array(
|
Self(Union::Array(
|
||||||
Box::new(value.into_iter().map(Dynamic::from).collect()),
|
Box::new(value.into_iter().map(Dynamic::from).collect()),
|
||||||
@ -2008,7 +2007,7 @@ impl<T: Variant + Clone> From<Vec<T>> for Dynamic {
|
|||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
impl<T: Variant + Clone> From<&[T]> for Dynamic {
|
impl<T: Variant + Clone> From<&[T]> for Dynamic {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from(value: &[T]) -> Self {
|
fn from(value: &[T]) -> Self {
|
||||||
Self(Union::Array(
|
Self(Union::Array(
|
||||||
Box::new(value.iter().cloned().map(Dynamic::from).collect()),
|
Box::new(value.iter().cloned().map(Dynamic::from).collect()),
|
||||||
@ -2019,7 +2018,7 @@ impl<T: Variant + Clone> From<&[T]> for Dynamic {
|
|||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
impl<T: Variant + Clone> std::iter::FromIterator<T> for Dynamic {
|
impl<T: Variant + Clone> std::iter::FromIterator<T> for Dynamic {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from_iter<X: IntoIterator<Item = T>>(iter: X) -> Self {
|
fn from_iter<X: IntoIterator<Item = T>>(iter: X) -> Self {
|
||||||
Self(Union::Array(
|
Self(Union::Array(
|
||||||
Box::new(iter.into_iter().map(Dynamic::from).collect()),
|
Box::new(iter.into_iter().map(Dynamic::from).collect()),
|
||||||
|
@ -144,7 +144,7 @@ impl Imports {
|
|||||||
}
|
}
|
||||||
/// Does the specified function hash key exist in this stack of imported [modules][Module]?
|
/// Does the specified function hash key exist in this stack of imported [modules][Module]?
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn contains_fn(&self, hash: u64) -> bool {
|
pub fn contains_fn(&self, hash: u64) -> bool {
|
||||||
self.modules.iter().any(|m| m.contains_qualified_fn(hash))
|
self.modules.iter().any(|m| m.contains_qualified_fn(hash))
|
||||||
@ -161,7 +161,7 @@ impl Imports {
|
|||||||
/// Does the specified [`TypeId`][std::any::TypeId] iterator exist in this stack of
|
/// Does the specified [`TypeId`][std::any::TypeId] iterator exist in this stack of
|
||||||
/// imported [modules][Module]?
|
/// imported [modules][Module]?
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn contains_iter(&self, id: TypeId) -> bool {
|
pub fn contains_iter(&self, id: TypeId) -> bool {
|
||||||
self.modules.iter().any(|m| m.contains_qualified_iter(id))
|
self.modules.iter().any(|m| m.contains_qualified_iter(id))
|
||||||
@ -888,7 +888,7 @@ impl<'x, 'px, 'pt> EvalContext<'_, 'x, 'px, '_, '_, '_, '_, 'pt> {
|
|||||||
self.mods
|
self.mods
|
||||||
}
|
}
|
||||||
/// Get an iterator over the namespaces containing definition of all script-defined functions.
|
/// Get an iterator over the namespaces containing definition of all script-defined functions.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter_namespaces(&self) -> impl Iterator<Item = &Module> {
|
pub fn iter_namespaces(&self) -> impl Iterator<Item = &Module> {
|
||||||
self.lib.iter().cloned()
|
self.lib.iter().cloned()
|
||||||
}
|
}
|
||||||
@ -3262,7 +3262,7 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// If a type is registered via [`register_type_with_name`][Engine::register_type_with_name],
|
/// If a type is registered via [`register_type_with_name`][Engine::register_type_with_name],
|
||||||
/// the type name provided for the registration will be used.
|
/// the type name provided for the registration will be used.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn map_type_name<'a>(&'a self, name: &'a str) -> &'a str {
|
pub fn map_type_name<'a>(&'a self, name: &'a str) -> &'a str {
|
||||||
self.type_names
|
self.type_names
|
||||||
@ -3272,7 +3272,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Make a `Box<`[`EvalAltResult<ErrorMismatchDataType>`][EvalAltResult::ErrorMismatchDataType]`>`.
|
/// Make a `Box<`[`EvalAltResult<ErrorMismatchDataType>`][EvalAltResult::ErrorMismatchDataType]`>`.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn make_type_mismatch_err<T>(&self, typ: &str, pos: Position) -> Box<EvalAltResult> {
|
pub(crate) fn make_type_mismatch_err<T>(&self, typ: &str, pos: Position) -> Box<EvalAltResult> {
|
||||||
EvalAltResult::ErrorMismatchDataType(
|
EvalAltResult::ErrorMismatchDataType(
|
||||||
|
@ -1287,7 +1287,7 @@ impl Engine {
|
|||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn compile_file_with_scope(
|
pub fn compile_file_with_scope(
|
||||||
&self,
|
&self,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
@ -1491,7 +1491,7 @@ impl Engine {
|
|||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn eval_file<T: Variant + Clone>(
|
pub fn eval_file<T: Variant + Clone>(
|
||||||
&self,
|
&self,
|
||||||
path: std::path::PathBuf,
|
path: std::path::PathBuf,
|
||||||
@ -1521,7 +1521,7 @@ impl Engine {
|
|||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn eval_file_with_scope<T: Variant + Clone>(
|
pub fn eval_file_with_scope<T: Variant + Clone>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
@ -1569,7 +1569,7 @@ impl Engine {
|
|||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn eval_with_scope<T: Variant + Clone>(
|
pub fn eval_with_scope<T: Variant + Clone>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
@ -1744,7 +1744,7 @@ impl Engine {
|
|||||||
/// Not available under `no_std` or `WASM`.
|
/// Not available under `no_std` or `WASM`.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn run_file(&self, path: std::path::PathBuf) -> Result<(), Box<EvalAltResult>> {
|
pub fn run_file(&self, path: std::path::PathBuf) -> Result<(), Box<EvalAltResult>> {
|
||||||
Self::read_file(path).and_then(|contents| self.run(&contents))
|
Self::read_file(path).and_then(|contents| self.run(&contents))
|
||||||
}
|
}
|
||||||
@ -1753,7 +1753,7 @@ impl Engine {
|
|||||||
/// Not available under `no_std` or `WASM`.
|
/// Not available under `no_std` or `WASM`.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn run_file_with_scope(
|
pub fn run_file_with_scope(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
|
@ -67,7 +67,7 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// Not available under `unchecked`.
|
/// Not available under `unchecked`.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn max_operations(&self) -> u64 {
|
pub const fn max_operations(&self) -> u64 {
|
||||||
if let Some(n) = self.limits.max_operations {
|
if let Some(n) = self.limits.max_operations {
|
||||||
@ -117,7 +117,7 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// Not available under `unchecked`.
|
/// Not available under `unchecked`.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn max_expr_depth(&self) -> usize {
|
pub const fn max_expr_depth(&self) -> usize {
|
||||||
if let Some(n) = self.limits.max_expr_depth {
|
if let Some(n) = self.limits.max_expr_depth {
|
||||||
@ -131,7 +131,7 @@ impl Engine {
|
|||||||
/// Not available under `unchecked` or `no_function`.
|
/// Not available under `unchecked` or `no_function`.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn max_function_expr_depth(&self) -> usize {
|
pub const fn max_function_expr_depth(&self) -> usize {
|
||||||
if let Some(n) = self.limits.max_function_expr_depth {
|
if let Some(n) = self.limits.max_function_expr_depth {
|
||||||
@ -153,7 +153,7 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// Not available under `unchecked`.
|
/// Not available under `unchecked`.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn max_string_size(&self) -> usize {
|
pub const fn max_string_size(&self) -> usize {
|
||||||
if let Some(n) = self.limits.max_string_size {
|
if let Some(n) = self.limits.max_string_size {
|
||||||
@ -177,7 +177,7 @@ impl Engine {
|
|||||||
/// Not available under `unchecked` or `no_index`.
|
/// Not available under `unchecked` or `no_index`.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn max_array_size(&self) -> usize {
|
pub const fn max_array_size(&self) -> usize {
|
||||||
if let Some(n) = self.limits.max_array_size {
|
if let Some(n) = self.limits.max_array_size {
|
||||||
@ -201,7 +201,7 @@ impl Engine {
|
|||||||
/// Not available under `unchecked` or `no_object`.
|
/// Not available under `unchecked` or `no_object`.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn max_map_size(&self) -> usize {
|
pub const fn max_map_size(&self) -> usize {
|
||||||
if let Some(n) = self.limits.max_map_size {
|
if let Some(n) = self.limits.max_map_size {
|
||||||
|
@ -57,7 +57,7 @@ pub trait FuncArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Variant + Clone> FuncArgs for Vec<T> {
|
impl<T: Variant + Clone> FuncArgs for Vec<T> {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn parse<CONTAINER: Extend<Dynamic>>(self, container: &mut CONTAINER) {
|
fn parse<CONTAINER: Extend<Dynamic>>(self, container: &mut CONTAINER) {
|
||||||
container.extend(self.into_iter().map(Variant::into_dynamic));
|
container.extend(self.into_iter().map(Variant::into_dynamic));
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ macro_rules! impl_args {
|
|||||||
($($p:ident),*) => {
|
($($p:ident),*) => {
|
||||||
impl<$($p: Variant + Clone),*> FuncArgs for ($($p,)*)
|
impl<$($p: Variant + Clone),*> FuncArgs for ($($p,)*)
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn parse<CONTAINER: Extend<Dynamic>>(self, container: &mut CONTAINER) {
|
fn parse<CONTAINER: Extend<Dynamic>>(self, container: &mut CONTAINER) {
|
||||||
let ($($p,)*) = self;
|
let ($($p,)*) = self;
|
||||||
|
@ -57,7 +57,7 @@ impl<'a> ArgBackup<'a> {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics when `args` is empty.
|
/// Panics when `args` is empty.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn change_first_arg_to_copy(&mut self, args: &mut FnCallArgs<'a>) {
|
fn change_first_arg_to_copy(&mut self, args: &mut FnCallArgs<'a>) {
|
||||||
// Clone the original value.
|
// Clone the original value.
|
||||||
self.value_copy = args[0].clone();
|
self.value_copy = args[0].clone();
|
||||||
@ -91,7 +91,7 @@ impl<'a> ArgBackup<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for ArgBackup<'_> {
|
impl Drop for ArgBackup<'_> {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// Panic if the shorter lifetime leaks.
|
// Panic if the shorter lifetime leaks.
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -96,13 +96,13 @@ macro_rules! def_anonymous_fn {
|
|||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
type Output = Box<dyn Fn($($par),*) -> Result<RET, Box<EvalAltResult>>>;
|
type Output = Box<dyn Fn($($par),*) -> Result<RET, Box<EvalAltResult>>>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output {
|
fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output {
|
||||||
let fn_name: SmartString = entry_point.into();
|
let fn_name: SmartString = entry_point.into();
|
||||||
Box::new(move |$($par),*| self.call_fn(&mut Scope::new(), &ast, &fn_name, ($($par,)*)))
|
Box::new(move |$($par),*| self.call_fn(&mut Scope::new(), &ast, &fn_name, ($($par,)*)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn create_from_script(self, script: &str, entry_point: &str) -> Result<Self::Output, ParseError> {
|
fn create_from_script(self, script: &str, entry_point: &str) -> Result<Self::Output, ParseError> {
|
||||||
let ast = self.compile(script)?;
|
let ast = self.compile(script)?;
|
||||||
Ok(Func::<($($par,)*), RET>::create_from_ast(self, ast, entry_point))
|
Ok(Func::<($($par,)*), RET>::create_from_ast(self, ast, entry_point))
|
||||||
|
@ -144,14 +144,14 @@ impl<'a> NativeCallContext<'a> {
|
|||||||
///
|
///
|
||||||
/// Not available under `no_module`.
|
/// Not available under `no_module`.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &Module)> {
|
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &Module)> {
|
||||||
self.mods.iter().flat_map(|&m| m.iter())
|
self.mods.iter().flat_map(|&m| m.iter())
|
||||||
}
|
}
|
||||||
/// Get an iterator over the current set of modules imported via `import` statements.
|
/// Get an iterator over the current set of modules imported via `import` statements.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn iter_imports_raw(
|
pub(crate) fn iter_imports_raw(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<Item = (&crate::Identifier, &Shared<Module>)> {
|
) -> impl Iterator<Item = (&crate::Identifier, &Shared<Module>)> {
|
||||||
@ -169,7 +169,7 @@ impl<'a> NativeCallContext<'a> {
|
|||||||
self.mods
|
self.mods
|
||||||
}
|
}
|
||||||
/// Get an iterator over the namespaces containing definitions of all script-defined functions.
|
/// Get an iterator over the namespaces containing definitions of all script-defined functions.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter_namespaces(&self) -> impl Iterator<Item = &Module> {
|
pub fn iter_namespaces(&self) -> impl Iterator<Item = &Module> {
|
||||||
self.lib.iter().cloned()
|
self.lib.iter().cloned()
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ pub fn shared_make_mut<T: Clone>(value: &mut Shared<T>) -> &mut T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Consume a [`Shared`] resource if is unique (i.e. not shared), or clone it otherwise.
|
/// Consume a [`Shared`] resource if is unique (i.e. not shared), or clone it otherwise.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn shared_take_or_clone<T: Clone>(value: Shared<T>) -> T {
|
pub fn shared_take_or_clone<T: Clone>(value: Shared<T>) -> T {
|
||||||
shared_try_take(value).unwrap_or_else(|v| v.as_ref().clone())
|
shared_try_take(value).unwrap_or_else(|v| v.as_ref().clone())
|
||||||
@ -256,7 +256,7 @@ pub fn shared_try_take<T>(value: Shared<T>) -> Result<T, Shared<T>> {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the resource is shared (i.e. has other outstanding references).
|
/// Panics if the resource is shared (i.e. has other outstanding references).
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn shared_take<T>(value: Shared<T>) -> T {
|
pub fn shared_take<T>(value: Shared<T>) -> T {
|
||||||
shared_try_take(value)
|
shared_try_take(value)
|
||||||
|
@ -69,7 +69,7 @@ impl FnPtr {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
/// Set curried arguments to the function pointer.
|
/// Set curried arguments to the function pointer.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn set_curry(&mut self, values: impl IntoIterator<Item = Dynamic>) -> &mut Self {
|
pub fn set_curry(&mut self, values: impl IntoIterator<Item = Dynamic>) -> &mut Self {
|
||||||
self.1 = values.into_iter().collect();
|
self.1 = values.into_iter().collect();
|
||||||
self
|
self
|
||||||
|
@ -90,26 +90,29 @@ impl Borrow<str> for ImmutableString {
|
|||||||
impl From<&str> for ImmutableString {
|
impl From<&str> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(value: &str) -> Self {
|
fn from(value: &str) -> Self {
|
||||||
Self(Into::<SmartString>::into(value).into())
|
let value: SmartString = value.into();
|
||||||
|
Self(value.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<&String> for ImmutableString {
|
impl From<&String> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(value: &String) -> Self {
|
fn from(value: &String) -> Self {
|
||||||
Self(Into::<SmartString>::into(value).into())
|
let value: SmartString = value.into();
|
||||||
|
Self(value.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<String> for ImmutableString {
|
impl From<String> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(value: String) -> Self {
|
fn from(value: String) -> Self {
|
||||||
Self(Into::<SmartString>::into(value).into())
|
let value: SmartString = value.into();
|
||||||
|
Self(value.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_smartstring"))]
|
#[cfg(not(feature = "no_smartstring"))]
|
||||||
impl From<&SmartString> for ImmutableString {
|
impl From<&SmartString> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(value: &SmartString) -> Self {
|
fn from(value: &SmartString) -> Self {
|
||||||
Self(Into::<SmartString>::into(value.as_str()).into())
|
Self(value.clone().into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_smartstring"))]
|
#[cfg(not(feature = "no_smartstring"))]
|
||||||
@ -137,33 +140,34 @@ impl FromStr for ImmutableString {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
Ok(Self(Into::<SmartString>::into(s).into()))
|
let s: SmartString = s.into();
|
||||||
|
Ok(Self(s.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromIterator<char> for ImmutableString {
|
impl FromIterator<char> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().collect::<SmartString>().into())
|
Self(iter.into_iter().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FromIterator<&'a char> for ImmutableString {
|
impl<'a> FromIterator<&'a char> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().cloned().collect::<SmartString>().into())
|
Self(iter.into_iter().cloned().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FromIterator<&'a str> for ImmutableString {
|
impl<'a> FromIterator<&'a str> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().collect::<SmartString>().into())
|
Self(iter.into_iter().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FromIterator<String> for ImmutableString {
|
impl<'a> FromIterator<String> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().collect::<SmartString>().into())
|
Self(iter.into_iter().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
@ -171,7 +175,7 @@ impl<'a> FromIterator<String> for ImmutableString {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_smartstring"))]
|
#[cfg(not(feature = "no_smartstring"))]
|
||||||
impl<'a> FromIterator<SmartString> for ImmutableString {
|
impl<'a> FromIterator<SmartString> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from_iter<T: IntoIterator<Item = SmartString>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = SmartString>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().collect::<SmartString>().into())
|
Self(iter.into_iter().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
@ -278,7 +282,7 @@ impl Add<&str> for &ImmutableString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AddAssign<&str> for ImmutableString {
|
impl AddAssign<&str> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn add_assign(&mut self, rhs: &str) {
|
fn add_assign(&mut self, rhs: &str) {
|
||||||
if !rhs.is_empty() {
|
if !rhs.is_empty() {
|
||||||
self.make_mut().push_str(rhs);
|
self.make_mut().push_str(rhs);
|
||||||
@ -324,7 +328,8 @@ impl AddAssign<String> for ImmutableString {
|
|||||||
fn add_assign(&mut self, rhs: String) {
|
fn add_assign(&mut self, rhs: String) {
|
||||||
if !rhs.is_empty() {
|
if !rhs.is_empty() {
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
self.0 = Into::<SmartString>::into(rhs).into();
|
let rhs: SmartString = rhs.into();
|
||||||
|
self.0 = rhs.into();
|
||||||
} else {
|
} else {
|
||||||
self.make_mut().push_str(&rhs);
|
self.make_mut().push_str(&rhs);
|
||||||
}
|
}
|
||||||
@ -335,7 +340,7 @@ impl AddAssign<String> for ImmutableString {
|
|||||||
impl Add<char> for ImmutableString {
|
impl Add<char> for ImmutableString {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn add(mut self, rhs: char) -> Self::Output {
|
fn add(mut self, rhs: char) -> Self::Output {
|
||||||
self.make_mut().push(rhs);
|
self.make_mut().push(rhs);
|
||||||
self
|
self
|
||||||
@ -345,7 +350,7 @@ impl Add<char> for ImmutableString {
|
|||||||
impl Add<char> for &ImmutableString {
|
impl Add<char> for &ImmutableString {
|
||||||
type Output = ImmutableString;
|
type Output = ImmutableString;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn add(self, rhs: char) -> Self::Output {
|
fn add(self, rhs: char) -> Self::Output {
|
||||||
let mut s = self.clone();
|
let mut s = self.clone();
|
||||||
s.make_mut().push(rhs);
|
s.make_mut().push(rhs);
|
||||||
@ -354,7 +359,7 @@ impl Add<char> for &ImmutableString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AddAssign<char> for ImmutableString {
|
impl AddAssign<char> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn add_assign(&mut self, rhs: char) {
|
fn add_assign(&mut self, rhs: char) {
|
||||||
self.make_mut().push(rhs);
|
self.make_mut().push(rhs);
|
||||||
}
|
}
|
||||||
@ -397,7 +402,8 @@ impl SubAssign<&ImmutableString> for ImmutableString {
|
|||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
self.0 = rhs.0.clone();
|
self.0 = rhs.0.clone();
|
||||||
} else {
|
} else {
|
||||||
self.0 = Into::<SmartString>::into(self.replace(rhs.as_str(), "")).into();
|
let rhs: SmartString = self.replace(rhs.as_str(), "").into();
|
||||||
|
self.0 = rhs.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -410,7 +416,8 @@ impl SubAssign<ImmutableString> for ImmutableString {
|
|||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
self.0 = rhs.0;
|
self.0 = rhs.0;
|
||||||
} else {
|
} else {
|
||||||
self.0 = Into::<SmartString>::into(self.replace(rhs.as_str(), "")).into();
|
let rhs: SmartString = self.replace(rhs.as_str(), "").into();
|
||||||
|
self.0 = rhs.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -447,9 +454,10 @@ impl Sub<String> for &ImmutableString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SubAssign<String> for ImmutableString {
|
impl SubAssign<String> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn sub_assign(&mut self, rhs: String) {
|
fn sub_assign(&mut self, rhs: String) {
|
||||||
self.0 = Into::<SmartString>::into(self.replace(&rhs, "")).into();
|
let rhs: SmartString = self.replace(&rhs, "").into();
|
||||||
|
self.0 = rhs.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,9 +480,10 @@ impl Sub<char> for &ImmutableString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SubAssign<char> for ImmutableString {
|
impl SubAssign<char> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn sub_assign(&mut self, rhs: char) {
|
fn sub_assign(&mut self, rhs: char) {
|
||||||
self.0 = Into::<SmartString>::into(self.replace(rhs, "")).into();
|
let rhs: SmartString = self.replace(rhs, "").into();
|
||||||
|
self.0 = rhs.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +536,7 @@ impl ImmutableString {
|
|||||||
}
|
}
|
||||||
/// Consume the [`ImmutableString`] and convert it into a [`String`].
|
/// Consume the [`ImmutableString`] and convert it into a [`String`].
|
||||||
/// If there are other references to the same string, a cloned copy is returned.
|
/// If there are other references to the same string, a cloned copy is returned.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn into_owned(mut self) -> String {
|
pub fn into_owned(mut self) -> String {
|
||||||
self.make_mut(); // Make sure it is unique reference
|
self.make_mut(); // Make sure it is unique reference
|
||||||
shared_take(self.0).into() // Should succeed
|
shared_take(self.0).into() // Should succeed
|
||||||
|
@ -204,7 +204,7 @@ impl AsRef<Module> for Module {
|
|||||||
impl<M: AsRef<Module>> Add<M> for &Module {
|
impl<M: AsRef<Module>> Add<M> for &Module {
|
||||||
type Output = Module;
|
type Output = Module;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn add(self, rhs: M) -> Self::Output {
|
fn add(self, rhs: M) -> Self::Output {
|
||||||
let mut module = self.clone();
|
let mut module = self.clone();
|
||||||
module.merge(rhs.as_ref());
|
module.merge(rhs.as_ref());
|
||||||
@ -240,7 +240,7 @@ impl Module {
|
|||||||
/// module.set_var("answer", 42_i64);
|
/// module.set_var("answer", 42_i64);
|
||||||
/// assert_eq!(module.get_var_value::<i64>("answer").expect("answer should exist"), 42);
|
/// assert_eq!(module.get_var_value::<i64>("answer").expect("answer should exist"), 42);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -269,7 +269,7 @@ impl Module {
|
|||||||
/// module.set_id("hello");
|
/// module.set_id("hello");
|
||||||
/// assert_eq!(module.id(), Some("hello"));
|
/// assert_eq!(module.id(), Some("hello"));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn id(&self) -> Option<&str> {
|
pub fn id(&self) -> Option<&str> {
|
||||||
self.id_raw().map(|s| s.as_str())
|
self.id_raw().map(|s| s.as_str())
|
||||||
@ -365,7 +365,7 @@ impl Module {
|
|||||||
/// Generate signatures for all the non-private functions in the [`Module`].
|
/// Generate signatures for all the non-private functions in the [`Module`].
|
||||||
/// Exported under the `metadata` feature only.
|
/// Exported under the `metadata` feature only.
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn gen_fn_signatures(&self) -> impl Iterator<Item = String> + '_ {
|
pub fn gen_fn_signatures(&self) -> impl Iterator<Item = String> + '_ {
|
||||||
self.functions
|
self.functions
|
||||||
.values()
|
.values()
|
||||||
@ -402,7 +402,7 @@ impl Module {
|
|||||||
/// module.set_var("answer", 42_i64);
|
/// module.set_var("answer", 42_i64);
|
||||||
/// assert_eq!(module.get_var_value::<i64>("answer").expect("answer should exist"), 42);
|
/// assert_eq!(module.get_var_value::<i64>("answer").expect("answer should exist"), 42);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_var_value<T: Variant + Clone>(&self, name: &str) -> Option<T> {
|
pub fn get_var_value<T: Variant + Clone>(&self, name: &str) -> Option<T> {
|
||||||
self.get_var(name).and_then(Dynamic::try_cast::<T>)
|
self.get_var(name).and_then(Dynamic::try_cast::<T>)
|
||||||
@ -559,7 +559,7 @@ impl Module {
|
|||||||
/// module.set_sub_module("question", sub_module);
|
/// module.set_sub_module("question", sub_module);
|
||||||
/// assert!(module.get_sub_module("question").is_some());
|
/// assert!(module.get_sub_module("question").is_some());
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_sub_module(&self, name: &str) -> Option<&Module> {
|
pub fn get_sub_module(&self, name: &str) -> Option<&Module> {
|
||||||
self.modules.get(name).map(|m| m.as_ref())
|
self.modules.get(name).map(|m| m.as_ref())
|
||||||
@ -1113,7 +1113,7 @@ impl Module {
|
|||||||
/// Get a Rust function.
|
/// Get a Rust function.
|
||||||
///
|
///
|
||||||
/// The [`u64`] hash is returned by the [`set_native_fn`][Module::set_native_fn] call.
|
/// The [`u64`] hash is returned by the [`set_native_fn`][Module::set_native_fn] call.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn get_fn(&self, hash_fn: u64) -> Option<&CallableFunction> {
|
pub(crate) fn get_fn(&self, hash_fn: u64) -> Option<&CallableFunction> {
|
||||||
self.functions.get(&hash_fn).map(|f| f.func.as_ref())
|
self.functions.get(&hash_fn).map(|f| f.func.as_ref())
|
||||||
@ -1131,7 +1131,7 @@ impl Module {
|
|||||||
/// Get a namespace-qualified function.
|
/// Get a namespace-qualified function.
|
||||||
///
|
///
|
||||||
/// The [`u64`] hash is calculated by [`build_index`][Module::build_index].
|
/// The [`u64`] hash is calculated by [`build_index`][Module::build_index].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn get_qualified_fn(&self, hash_qualified_fn: u64) -> Option<&CallableFunction> {
|
pub(crate) fn get_qualified_fn(&self, hash_qualified_fn: u64) -> Option<&CallableFunction> {
|
||||||
self.all_functions
|
self.all_functions
|
||||||
@ -1289,19 +1289,19 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get an iterator to the sub-modules in the [`Module`].
|
/// Get an iterator to the sub-modules in the [`Module`].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter_sub_modules(&self) -> impl Iterator<Item = (&str, Shared<Module>)> {
|
pub fn iter_sub_modules(&self) -> impl Iterator<Item = (&str, Shared<Module>)> {
|
||||||
self.modules.iter().map(|(k, m)| (k.as_str(), m.clone()))
|
self.modules.iter().map(|(k, m)| (k.as_str(), m.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an iterator to the variables in the [`Module`].
|
/// Get an iterator to the variables in the [`Module`].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter_var(&self) -> impl Iterator<Item = (&str, &Dynamic)> {
|
pub fn iter_var(&self) -> impl Iterator<Item = (&str, &Dynamic)> {
|
||||||
self.variables.iter().map(|(k, v)| (k.as_str(), v))
|
self.variables.iter().map(|(k, v)| (k.as_str(), v))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an iterator to the functions in the [`Module`].
|
/// Get an iterator to the functions in the [`Module`].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn iter_fn(&self) -> impl Iterator<Item = &FuncInfo> {
|
pub(crate) fn iter_fn(&self) -> impl Iterator<Item = &FuncInfo> {
|
||||||
self.functions.values().map(Box::as_ref)
|
self.functions.values().map(Box::as_ref)
|
||||||
@ -1316,7 +1316,7 @@ impl Module {
|
|||||||
/// 4) Number of parameters.
|
/// 4) Number of parameters.
|
||||||
/// 5) Shared reference to function definition [`ScriptFnDef`][crate::ast::ScriptFnDef].
|
/// 5) Shared reference to function definition [`ScriptFnDef`][crate::ast::ScriptFnDef].
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn iter_script_fn(
|
pub(crate) fn iter_script_fn(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<
|
) -> impl Iterator<
|
||||||
@ -1351,7 +1351,7 @@ impl Module {
|
|||||||
/// 4) Number of parameters.
|
/// 4) Number of parameters.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[cfg(not(feature = "internals"))]
|
#[cfg(not(feature = "internals"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter_script_fn_info(
|
pub fn iter_script_fn_info(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<Item = (FnNamespace, FnAccess, &str, usize)> {
|
) -> impl Iterator<Item = (FnNamespace, FnAccess, &str, usize)> {
|
||||||
@ -1610,7 +1610,7 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set a type iterator into the [`Module`].
|
/// Set a type iterator into the [`Module`].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn set_iterable<T>(&mut self) -> &mut Self
|
pub fn set_iterable<T>(&mut self) -> &mut Self
|
||||||
where
|
where
|
||||||
T: Variant + Clone + IntoIterator,
|
T: Variant + Clone + IntoIterator,
|
||||||
@ -1622,7 +1622,7 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set an iterator type into the [`Module`] as a type iterator.
|
/// Set an iterator type into the [`Module`] as a type iterator.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn set_iterator<T>(&mut self) -> &mut Self
|
pub fn set_iterator<T>(&mut self) -> &mut Self
|
||||||
where
|
where
|
||||||
T: Variant + Clone + Iterator,
|
T: Variant + Clone + Iterator,
|
||||||
@ -1634,14 +1634,14 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the specified type iterator.
|
/// Get the specified type iterator.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn get_qualified_iter(&self, id: TypeId) -> Option<IteratorFn> {
|
pub(crate) fn get_qualified_iter(&self, id: TypeId) -> Option<IteratorFn> {
|
||||||
self.all_type_iterators.get(&id).cloned()
|
self.all_type_iterators.get(&id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the specified type iterator.
|
/// Get the specified type iterator.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn get_iter(&self, id: TypeId) -> Option<IteratorFn> {
|
pub(crate) fn get_iter(&self, id: TypeId) -> Option<IteratorFn> {
|
||||||
self.type_iterators.get(&id).cloned()
|
self.type_iterators.get(&id).cloned()
|
||||||
@ -1709,8 +1709,7 @@ impl DerefMut for NamespaceRef {
|
|||||||
|
|
||||||
impl From<StaticVec<Ident>> for NamespaceRef {
|
impl From<StaticVec<Ident>> for NamespaceRef {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(path: StaticVec<Ident>) -> Self {
|
fn from(mut path: StaticVec<Ident>) -> Self {
|
||||||
let mut path = path;
|
|
||||||
path.shrink_to_fit();
|
path.shrink_to_fit();
|
||||||
Self { index: None, path }
|
Self { index: None, path }
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ impl ModuleResolversCollection {
|
|||||||
self.0.remove(index)
|
self.0.remove(index)
|
||||||
}
|
}
|
||||||
/// Get an iterator of all the [module resolvers][ModuleResolver].
|
/// Get an iterator of all the [module resolvers][ModuleResolver].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter(&self) -> impl Iterator<Item = &dyn ModuleResolver> {
|
pub fn iter(&self) -> impl Iterator<Item = &dyn ModuleResolver> {
|
||||||
self.0.iter().map(|v| v.as_ref())
|
self.0.iter().map(|v| v.as_ref())
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ impl ModuleResolversCollection {
|
|||||||
}
|
}
|
||||||
/// Add another [`ModuleResolversCollection`] to the end of this collection.
|
/// Add another [`ModuleResolversCollection`] to the end of this collection.
|
||||||
/// The other [`ModuleResolversCollection`] is consumed.
|
/// The other [`ModuleResolversCollection`] is consumed.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn append(&mut self, other: Self) -> &mut Self {
|
pub fn append(&mut self, other: Self) -> &mut Self {
|
||||||
self.0.extend(other.0.into_iter());
|
self.0.extend(other.0.into_iter());
|
||||||
self
|
self
|
||||||
|
@ -215,7 +215,7 @@ impl FileModuleResolver {
|
|||||||
return self.cache.write().unwrap().contains_key(&file_path);
|
return self.cache.write().unwrap().contains_key(&file_path);
|
||||||
}
|
}
|
||||||
/// Empty the internal cache.
|
/// Empty the internal cache.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn clear_cache(&mut self) -> &mut Self {
|
pub fn clear_cache(&mut self) -> &mut Self {
|
||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
self.cache.borrow_mut().clear();
|
self.cache.borrow_mut().clear();
|
||||||
|
@ -48,7 +48,7 @@ impl StaticModuleResolver {
|
|||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
/// Add a [module][Module] keyed by its path.
|
/// Add a [module][Module] keyed by its path.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn insert(&mut self, path: impl Into<Identifier>, mut module: Module) {
|
pub fn insert(&mut self, path: impl Into<Identifier>, mut module: Module) {
|
||||||
module.build_index();
|
module.build_index();
|
||||||
self.0.insert(path.into(), module.into());
|
self.0.insert(path.into(), module.into());
|
||||||
@ -65,17 +65,17 @@ impl StaticModuleResolver {
|
|||||||
self.0.contains_key(path)
|
self.0.contains_key(path)
|
||||||
}
|
}
|
||||||
/// Get an iterator of all the [modules][Module].
|
/// Get an iterator of all the [modules][Module].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter(&self) -> impl Iterator<Item = (&str, &Shared<Module>)> {
|
pub fn iter(&self) -> impl Iterator<Item = (&str, &Shared<Module>)> {
|
||||||
self.0.iter().map(|(k, v)| (k.as_str(), v))
|
self.0.iter().map(|(k, v)| (k.as_str(), v))
|
||||||
}
|
}
|
||||||
/// Get a mutable iterator of all the [modules][Module].
|
/// Get a mutable iterator of all the [modules][Module].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)> {
|
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)> {
|
||||||
self.0.iter_mut().map(|(k, v)| (k.as_str(), v))
|
self.0.iter_mut().map(|(k, v)| (k.as_str(), v))
|
||||||
}
|
}
|
||||||
/// Get an iterator of all the [module][Module] paths.
|
/// Get an iterator of all the [module][Module] paths.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn paths(&self) -> impl Iterator<Item = &str> {
|
pub fn paths(&self) -> impl Iterator<Item = &str> {
|
||||||
self.0.keys().map(|s| s.as_str())
|
self.0.keys().map(|s| s.as_str())
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ impl StaticModuleResolver {
|
|||||||
/// The other [`StaticModuleResolver`] is consumed.
|
/// The other [`StaticModuleResolver`] is consumed.
|
||||||
///
|
///
|
||||||
/// Existing modules of the same path name are overwritten.
|
/// Existing modules of the same path name are overwritten.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn merge(&mut self, other: Self) -> &mut Self {
|
pub fn merge(&mut self, other: Self) -> &mut Self {
|
||||||
if !other.is_empty() {
|
if !other.is_empty() {
|
||||||
self.0.extend(other.0.into_iter());
|
self.0.extend(other.0.into_iter());
|
||||||
@ -124,7 +124,7 @@ impl IntoIterator for StaticModuleResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleResolver for StaticModuleResolver {
|
impl ModuleResolver for StaticModuleResolver {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn resolve(
|
fn resolve(
|
||||||
&self,
|
&self,
|
||||||
_: &Engine,
|
_: &Engine,
|
||||||
|
@ -123,7 +123,7 @@ impl<'a> OptimizerState<'a> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
/// Call a registered function
|
/// Call a registered function
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn call_fn_with_constant_arguments(
|
pub fn call_fn_with_constant_arguments(
|
||||||
&self,
|
&self,
|
||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
|
@ -251,7 +251,7 @@ impl Iterator for CharsStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
let remaining = self.0.len() - self.1;
|
let remaining = self.0.len() - self.1;
|
||||||
(remaining, Some(remaining))
|
(remaining, Some(remaining))
|
||||||
@ -261,7 +261,7 @@ impl Iterator for CharsStream {
|
|||||||
impl FusedIterator for CharsStream {}
|
impl FusedIterator for CharsStream {}
|
||||||
|
|
||||||
impl ExactSizeIterator for CharsStream {
|
impl ExactSizeIterator for CharsStream {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
||||||
self.0.len() - self.1
|
self.0.len() - self.1
|
||||||
}
|
}
|
||||||
|
@ -3322,7 +3322,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Run the parser on an input stream, returning an AST.
|
/// Run the parser on an input stream, returning an AST.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn parse(
|
pub(crate) fn parse(
|
||||||
&self,
|
&self,
|
||||||
input: &mut TokenStream,
|
input: &mut TokenStream,
|
||||||
|
@ -482,7 +482,7 @@ impl<'a> Scope<'a> {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the index is out of bounds.
|
/// Panics if the index is out of bounds.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn get_mut_by_index(&mut self, index: usize) -> &mut Dynamic {
|
pub(crate) fn get_mut_by_index(&mut self, index: usize) -> &mut Dynamic {
|
||||||
self.values.get_mut(index).expect("index is out of bounds")
|
self.values.get_mut(index).expect("index is out of bounds")
|
||||||
@ -565,7 +565,7 @@ impl<'a> Scope<'a> {
|
|||||||
/// assert!(is_constant);
|
/// assert!(is_constant);
|
||||||
/// assert_eq!(value.cast::<String>(), "hello");
|
/// assert_eq!(value.cast::<String>(), "hello");
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn iter(&self) -> impl Iterator<Item = (&str, bool, Dynamic)> {
|
pub fn iter(&self) -> impl Iterator<Item = (&str, bool, Dynamic)> {
|
||||||
self.iter_raw()
|
self.iter_raw()
|
||||||
.map(|(name, constant, value)| (name, constant, value.flatten_clone()))
|
.map(|(name, constant, value)| (name, constant, value.flatten_clone()))
|
||||||
@ -582,7 +582,7 @@ impl<'a> Scope<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, K: Into<Cow<'a, str>>> Extend<(K, Dynamic)> for Scope<'a> {
|
impl<'a, K: Into<Cow<'a, str>>> Extend<(K, Dynamic)> for Scope<'a> {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn extend<T: IntoIterator<Item = (K, Dynamic)>>(&mut self, iter: T) {
|
fn extend<T: IntoIterator<Item = (K, Dynamic)>>(&mut self, iter: T) {
|
||||||
iter.into_iter().for_each(|(name, value)| {
|
iter.into_iter().for_each(|(name, value)| {
|
||||||
self.names.push((name.into(), Default::default()));
|
self.names.push((name.into(), Default::default()));
|
||||||
|
20
src/token.rs
20
src/token.rs
@ -113,7 +113,7 @@ impl Position {
|
|||||||
/// If `line` is zero, then [`None`] is returned.
|
/// If `line` is zero, then [`None`] is returned.
|
||||||
///
|
///
|
||||||
/// If `position` is zero, then it is at the beginning of a line.
|
/// If `position` is zero, then it is at the beginning of a line.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn new_const(line: u16, position: u16) -> Option<Self> {
|
pub const fn new_const(line: u16, position: u16) -> Option<Self> {
|
||||||
if line == 0 {
|
if line == 0 {
|
||||||
@ -129,7 +129,7 @@ impl Position {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
/// Get the line number (1-based), or [`None`] if there is no position.
|
/// Get the line number (1-based), or [`None`] if there is no position.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn line(self) -> Option<usize> {
|
pub const fn line(self) -> Option<usize> {
|
||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
@ -143,7 +143,7 @@ impl Position {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
/// Get the character position (1-based), or [`None`] if at beginning of a line.
|
/// Get the character position (1-based), or [`None`] if at beginning of a line.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn position(self) -> Option<usize> {
|
pub const fn position(self) -> Option<usize> {
|
||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
@ -157,7 +157,7 @@ impl Position {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
/// Advance by one character position.
|
/// Advance by one character position.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn advance(&mut self) {
|
pub(crate) fn advance(&mut self) {
|
||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
{
|
{
|
||||||
@ -174,7 +174,7 @@ impl Position {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if already at beginning of a line - cannot rewind to a previous line.
|
/// Panics if already at beginning of a line - cannot rewind to a previous line.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn rewind(&mut self) {
|
pub(crate) fn rewind(&mut self) {
|
||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
{
|
{
|
||||||
@ -184,7 +184,7 @@ impl Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Advance to the next line.
|
/// Advance to the next line.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn new_line(&mut self) {
|
pub(crate) fn new_line(&mut self) {
|
||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
{
|
{
|
||||||
@ -198,7 +198,7 @@ impl Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this [`Position`] at the beginning of a line?
|
/// Is this [`Position`] at the beginning of a line?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_beginning_of_line(self) -> bool {
|
pub const fn is_beginning_of_line(self) -> bool {
|
||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
@ -207,7 +207,7 @@ impl Position {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/// Is there no [`Position`]?
|
/// Is there no [`Position`]?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_none(self) -> bool {
|
pub const fn is_none(self) -> bool {
|
||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
@ -216,7 +216,7 @@ impl Position {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// Print this [`Position`] for debug purposes.
|
/// Print this [`Position`] for debug purposes.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn debug_print(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
pub(crate) fn debug_print(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
if !self.is_none() {
|
if !self.is_none() {
|
||||||
@ -1352,7 +1352,7 @@ fn is_numeric_digit(c: char) -> bool {
|
|||||||
/// Test if the comment block is a doc-comment.
|
/// Test if the comment block is a doc-comment.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_doc_comment(comment: &str) -> bool {
|
pub fn is_doc_comment(comment: &str) -> bool {
|
||||||
(comment.starts_with("///") && !comment.starts_with("////"))
|
(comment.starts_with("///") && !comment.starts_with("////"))
|
||||||
|
@ -8,7 +8,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Cast a type into another type.
|
/// Cast a type into another type.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn unsafe_try_cast<A: Any, B: Any>(a: A) -> Result<B, A> {
|
pub fn unsafe_try_cast<A: Any, B: Any>(a: A) -> Result<B, A> {
|
||||||
if TypeId::of::<B>() == a.type_id() {
|
if TypeId::of::<B>() == a.type_id() {
|
||||||
// SAFETY: Just checked we have the right type. We explicitly forget the
|
// SAFETY: Just checked we have the right type. We explicitly forget the
|
||||||
@ -25,7 +25,7 @@ pub fn unsafe_try_cast<A: Any, B: Any>(a: A) -> Result<B, A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Cast a Boxed type into another type.
|
/// Cast a Boxed type into another type.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn unsafe_cast_box<X: Any, T: Any>(item: Box<X>) -> Result<Box<T>, Box<X>> {
|
pub fn unsafe_cast_box<X: Any, T: Any>(item: Box<X>) -> Result<Box<T>, Box<X>> {
|
||||||
// Only allow casting to the exact same type
|
// Only allow casting to the exact same type
|
||||||
if TypeId::of::<X>() == TypeId::of::<T>() {
|
if TypeId::of::<X>() == TypeId::of::<T>() {
|
||||||
|
Loading…
Reference in New Issue
Block a user