Shut up clippy.
This commit is contained in:
parent
1389541e7d
commit
80772df4f4
@ -989,7 +989,7 @@ impl Engine {
|
|||||||
} else {
|
} else {
|
||||||
let abs_index = index.unsigned_abs();
|
let abs_index = index.unsigned_abs();
|
||||||
|
|
||||||
if abs_index as u64 >= usize::MAX as u64 {
|
if abs_index as u64 > usize::MAX as u64 {
|
||||||
return Err(
|
return Err(
|
||||||
ERR::ErrorStringBounds(s.chars().count(), index, idx_pos).into()
|
ERR::ErrorStringBounds(s.chars().count(), index, idx_pos).into()
|
||||||
);
|
);
|
||||||
|
@ -397,7 +397,7 @@ impl Debugger {
|
|||||||
/// Get the custom state.
|
/// Get the custom state.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn state(&self) -> &Dynamic {
|
pub const fn state(&self) -> &Dynamic {
|
||||||
&self.state
|
&self.state
|
||||||
}
|
}
|
||||||
/// Get a mutable reference to the custom state.
|
/// Get a mutable reference to the custom state.
|
||||||
|
@ -144,11 +144,10 @@ impl Engine {
|
|||||||
let (index, var_pos) = match expr {
|
let (index, var_pos) = match expr {
|
||||||
// Check if the variable is `this`
|
// Check if the variable is `this`
|
||||||
Expr::Variable(v, None, pos) if v.0.is_none() && v.3 == KEYWORD_THIS => {
|
Expr::Variable(v, None, pos) if v.0.is_none() && v.3 == KEYWORD_THIS => {
|
||||||
return if let Some(val) = this_ptr {
|
return this_ptr.as_mut().map_or_else(
|
||||||
Ok(((*val).into(), *pos))
|
|| Err(ERR::ErrorUnboundThis(*pos).into()),
|
||||||
} else {
|
|val| Ok(((*val).into(), *pos)),
|
||||||
Err(ERR::ErrorUnboundThis(*pos).into())
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ if global.always_search_scope => (0, expr.start_position()),
|
_ if global.always_search_scope => (0, expr.start_position()),
|
||||||
Expr::Variable(.., Some(i), pos) => (i.get() as usize, *pos),
|
Expr::Variable(.., Some(i), pos) => (i.get() as usize, *pos),
|
||||||
|
@ -484,12 +484,10 @@ impl Engine {
|
|||||||
self.eval_expr(scope, global, caches, lib, this_ptr, expr, level)
|
self.eval_expr(scope, global, caches, lib, this_ptr, expr, level)
|
||||||
} else if let Ok(None) = expr_result {
|
} else if let Ok(None) = expr_result {
|
||||||
// Default match clause
|
// Default match clause
|
||||||
if let Some(index) = def_case {
|
def_case.as_ref().map_or(Ok(Dynamic::UNIT), |&index| {
|
||||||
let def_expr = &expressions[*index].expr;
|
let def_expr = &expressions[index].expr;
|
||||||
self.eval_expr(scope, global, caches, lib, this_ptr, def_expr, level)
|
self.eval_expr(scope, global, caches, lib, this_ptr, def_expr, level)
|
||||||
} else {
|
})
|
||||||
Ok(Dynamic::UNIT)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
expr_result.map(|_| Dynamic::UNIT)
|
expr_result.map(|_| Dynamic::UNIT)
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,12 @@ use std::prelude::v1::*;
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn calc_offset_len(length: usize, start: crate::INT, len: crate::INT) -> (usize, usize) {
|
pub fn calc_offset_len(length: usize, start: crate::INT, len: crate::INT) -> (usize, usize) {
|
||||||
let start = if start < 0 {
|
let start = if start < 0 {
|
||||||
length - usize::min(start.unsigned_abs() as usize, length)
|
let abs_start = start.unsigned_abs();
|
||||||
|
if abs_start as u64 > crate::MAX_USIZE_INT as u64 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
length - usize::min(abs_start as usize, length)
|
||||||
|
}
|
||||||
} else if start > crate::MAX_USIZE_INT || start as usize >= length {
|
} else if start > crate::MAX_USIZE_INT || start as usize >= length {
|
||||||
return (length, 0);
|
return (length, 0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1228,13 +1228,11 @@ impl Engine {
|
|||||||
|
|
||||||
if target_is_shared || target.is_temp_value() {
|
if target_is_shared || target.is_temp_value() {
|
||||||
arg_values.insert(0, target.take_or_clone().flatten());
|
arg_values.insert(0, target.take_or_clone().flatten());
|
||||||
args.extend(arg_values.iter_mut());
|
|
||||||
} else {
|
} else {
|
||||||
// Turn it into a method call only if the object is not shared and not a simple value
|
// Turn it into a method call only if the object is not shared and not a simple value
|
||||||
is_ref_mut = true;
|
is_ref_mut = true;
|
||||||
let obj_ref = target.take_ref().expect("ref");
|
let obj_ref = target.take_ref().expect("ref");
|
||||||
args.push(obj_ref);
|
args.push(obj_ref);
|
||||||
args.extend(arg_values.iter_mut());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// func(..., ...)
|
// func(..., ...)
|
||||||
@ -1246,8 +1244,9 @@ impl Engine {
|
|||||||
.map(|(value, ..)| arg_values.push(value.flatten()))
|
.map(|(value, ..)| arg_values.push(value.flatten()))
|
||||||
})?;
|
})?;
|
||||||
args.extend(curry.iter_mut());
|
args.extend(curry.iter_mut());
|
||||||
args.extend(arg_values.iter_mut());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args.extend(arg_values.iter_mut());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.exec_fn_call(
|
self.exec_fn_call(
|
||||||
|
@ -41,7 +41,7 @@ impl FnNamespace {
|
|||||||
/// Is this a module namespace?
|
/// Is this a module namespace?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_module_namespace(self) -> bool {
|
pub const fn is_module_namespace(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Internal => true,
|
Self::Internal => true,
|
||||||
Self::Global => false,
|
Self::Global => false,
|
||||||
@ -50,7 +50,7 @@ impl FnNamespace {
|
|||||||
/// Is this a global namespace?
|
/// Is this a global namespace?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_global_namespace(self) -> bool {
|
pub const fn is_global_namespace(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Internal => false,
|
Self::Internal => false,
|
||||||
Self::Global => true,
|
Self::Global => true,
|
||||||
@ -193,7 +193,6 @@ impl FuncInfo {
|
|||||||
sig.push_str(", ");
|
sig.push_str(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sig.push(')');
|
|
||||||
} else {
|
} else {
|
||||||
let params: StaticVec<_> = self
|
let params: StaticVec<_> = self
|
||||||
.metadata
|
.metadata
|
||||||
@ -215,8 +214,8 @@ impl FuncInfo {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
sig.push_str(¶ms.join(", "));
|
sig.push_str(¶ms.join(", "));
|
||||||
sig.push(')');
|
|
||||||
}
|
}
|
||||||
|
sig.push(')');
|
||||||
|
|
||||||
if !self.func.is_script() && !return_type.is_empty() {
|
if !self.func.is_script() && !return_type.is_empty() {
|
||||||
sig.push_str(" -> ");
|
sig.push_str(" -> ");
|
||||||
|
@ -988,7 +988,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) {
|
|||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
Expr::Index(x, ..) if !_chaining => match (&mut x.lhs, &mut x.rhs) {
|
Expr::Index(x, ..) if !_chaining => match (&mut x.lhs, &mut x.rhs) {
|
||||||
// array[int]
|
// array[int]
|
||||||
(Expr::Array(a, pos), Expr::IntegerConstant(i, ..)) if *i >= 0 && (*i as usize) < a.len() && a.iter().all(Expr::is_pure) => {
|
(Expr::Array(a, pos), Expr::IntegerConstant(i, ..)) if *i >= 0 && *i <= crate::MAX_USIZE_INT && (*i as usize) < a.len() && a.iter().all(Expr::is_pure) => {
|
||||||
// Array literal where everything is pure - promote the indexed item.
|
// Array literal where everything is pure - promote the indexed item.
|
||||||
// All other items can be thrown away.
|
// All other items can be thrown away.
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
@ -997,7 +997,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) {
|
|||||||
*expr = result;
|
*expr = result;
|
||||||
}
|
}
|
||||||
// array[-int]
|
// array[-int]
|
||||||
(Expr::Array(a, pos), Expr::IntegerConstant(i, ..)) if *i < 0 && i.unsigned_abs() as usize <= a.len() && a.iter().all(Expr::is_pure) => {
|
(Expr::Array(a, pos), Expr::IntegerConstant(i, ..)) if *i < 0 && i.unsigned_abs() as u64 <= a.len() as u64 && a.iter().all(Expr::is_pure) => {
|
||||||
// Array literal where everything is pure - promote the indexed item.
|
// Array literal where everything is pure - promote the indexed item.
|
||||||
// All other items can be thrown away.
|
// All other items can be thrown away.
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
@ -1015,25 +1015,25 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) {
|
|||||||
.map_or_else(|| Expr::Unit(*pos), |(.., mut expr)| { expr.set_position(*pos); expr });
|
.map_or_else(|| Expr::Unit(*pos), |(.., mut expr)| { expr.set_position(*pos); expr });
|
||||||
}
|
}
|
||||||
// int[int]
|
// int[int]
|
||||||
(Expr::IntegerConstant(n, pos), Expr::IntegerConstant(i, ..)) if *i >= 0 && (*i as usize) < crate::INT_BITS => {
|
(Expr::IntegerConstant(n, pos), Expr::IntegerConstant(i, ..)) if *i >= 0 && *i <= crate::MAX_USIZE_INT && (*i as usize) < crate::INT_BITS => {
|
||||||
// Bit-field literal indexing - get the bit
|
// Bit-field literal indexing - get the bit
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
*expr = Expr::BoolConstant((*n & (1 << (*i as usize))) != 0, *pos);
|
*expr = Expr::BoolConstant((*n & (1 << (*i as usize))) != 0, *pos);
|
||||||
}
|
}
|
||||||
// int[-int]
|
// int[-int]
|
||||||
(Expr::IntegerConstant(n, pos), Expr::IntegerConstant(i, ..)) if *i < 0 && i.unsigned_abs() as usize <= crate::INT_BITS => {
|
(Expr::IntegerConstant(n, pos), Expr::IntegerConstant(i, ..)) if *i < 0 && i.unsigned_abs() as u64 <= crate::INT_BITS as u64 => {
|
||||||
// Bit-field literal indexing - get the bit
|
// Bit-field literal indexing - get the bit
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
*expr = Expr::BoolConstant((*n & (1 << (crate::INT_BITS - i.unsigned_abs() as usize))) != 0, *pos);
|
*expr = Expr::BoolConstant((*n & (1 << (crate::INT_BITS - i.unsigned_abs() as usize))) != 0, *pos);
|
||||||
}
|
}
|
||||||
// string[int]
|
// string[int]
|
||||||
(Expr::StringConstant(s, pos), Expr::IntegerConstant(i, ..)) if *i >= 0 && (*i as usize) < s.chars().count() => {
|
(Expr::StringConstant(s, pos), Expr::IntegerConstant(i, ..)) if *i >= 0 && *i <= crate::MAX_USIZE_INT && (*i as usize) < s.chars().count() => {
|
||||||
// String literal indexing - get the character
|
// String literal indexing - get the character
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
*expr = Expr::CharConstant(s.chars().nth(*i as usize).unwrap(), *pos);
|
*expr = Expr::CharConstant(s.chars().nth(*i as usize).unwrap(), *pos);
|
||||||
}
|
}
|
||||||
// string[-int]
|
// string[-int]
|
||||||
(Expr::StringConstant(s, pos), Expr::IntegerConstant(i, ..)) if *i < 0 && i.unsigned_abs() as usize <= s.chars().count() => {
|
(Expr::StringConstant(s, pos), Expr::IntegerConstant(i, ..)) if *i < 0 && i.unsigned_abs() as u64 <= s.chars().count() as u64 => {
|
||||||
// String literal indexing - get the character
|
// String literal indexing - get the character
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
*expr = Expr::CharConstant(s.chars().rev().nth(i.unsigned_abs() as usize - 1).unwrap(), *pos);
|
*expr = Expr::CharConstant(s.chars().rev().nth(i.unsigned_abs() as usize - 1).unwrap(), *pos);
|
||||||
|
@ -1312,8 +1312,7 @@ pub mod array_functions {
|
|||||||
///
|
///
|
||||||
/// print(x); // prints "[1, 2, 3, 4, 3, 2, 1]"
|
/// print(x); // prints "[1, 2, 3, 4, 3, 2, 1]"
|
||||||
/// ```
|
/// ```
|
||||||
#[rhai_fn(return_raw)]
|
pub fn dedup(ctx: NativeCallContext, array: &mut Array) {
|
||||||
pub fn dedup(ctx: NativeCallContext, array: &mut Array) -> RhaiResultOf<()> {
|
|
||||||
let comparer = FnPtr::new_unchecked(OP_EQUALS, StaticVec::new_const());
|
let comparer = FnPtr::new_unchecked(OP_EQUALS, StaticVec::new_const());
|
||||||
dedup_by_comparer(ctx, array, comparer)
|
dedup_by_comparer(ctx, array, comparer)
|
||||||
}
|
}
|
||||||
@ -1340,14 +1339,10 @@ pub mod array_functions {
|
|||||||
///
|
///
|
||||||
/// print(x); // prints "[1, 2, 3, 4]"
|
/// print(x); // prints "[1, 2, 3, 4]"
|
||||||
/// ```
|
/// ```
|
||||||
#[rhai_fn(name = "dedup", return_raw)]
|
#[rhai_fn(name = "dedup")]
|
||||||
pub fn dedup_by_comparer(
|
pub fn dedup_by_comparer(ctx: NativeCallContext, array: &mut Array, comparer: FnPtr) {
|
||||||
ctx: NativeCallContext,
|
|
||||||
array: &mut Array,
|
|
||||||
comparer: FnPtr,
|
|
||||||
) -> RhaiResultOf<()> {
|
|
||||||
if array.is_empty() {
|
if array.is_empty() {
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
array.dedup_by(|x, y| {
|
array.dedup_by(|x, y| {
|
||||||
@ -1357,8 +1352,6 @@ pub mod array_functions {
|
|||||||
.as_bool()
|
.as_bool()
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
/// Remove duplicated _consecutive_ elements from the array that return `true` when applied a
|
/// Remove duplicated _consecutive_ elements from the array that return `true` when applied a
|
||||||
/// function named by `comparer`.
|
/// function named by `comparer`.
|
||||||
@ -1391,7 +1384,7 @@ pub mod array_functions {
|
|||||||
array: &mut Array,
|
array: &mut Array,
|
||||||
comparer: &str,
|
comparer: &str,
|
||||||
) -> RhaiResultOf<()> {
|
) -> RhaiResultOf<()> {
|
||||||
dedup_by_comparer(ctx, array, FnPtr::new(comparer)?)
|
Ok(dedup_by_comparer(ctx, array, FnPtr::new(comparer)?))
|
||||||
}
|
}
|
||||||
/// Reduce an array by iterating through all elements while applying the `reducer` function.
|
/// Reduce an array by iterating through all elements while applying the `reducer` function.
|
||||||
///
|
///
|
||||||
|
@ -22,7 +22,7 @@ impl<'de> DynamicDeserializer<'de> {
|
|||||||
/// The reference is necessary because the deserialized type may hold references
|
/// The reference is necessary because the deserialized type may hold references
|
||||||
/// (especially `&str`) to the source [`Dynamic`][crate::Dynamic].
|
/// (especially `&str`) to the source [`Dynamic`][crate::Dynamic].
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn from_dynamic(value: &'de Dynamic) -> Self {
|
pub const fn from_dynamic(value: &'de Dynamic) -> Self {
|
||||||
Self { value }
|
Self { value }
|
||||||
}
|
}
|
||||||
/// Shortcut for a type conversion error.
|
/// Shortcut for a type conversion error.
|
||||||
@ -449,7 +449,9 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
|
|||||||
visitor.visit_enum(s.as_str().into_deserializer())
|
visitor.visit_enum(s.as_str().into_deserializer())
|
||||||
} else {
|
} else {
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
if let Some(map) = self.value.downcast_ref::<crate::Map>() {
|
return self.value.downcast_ref::<crate::Map>().map_or_else(
|
||||||
|
|| self.type_error(),
|
||||||
|
|map| {
|
||||||
let mut iter = map.iter();
|
let mut iter = map.iter();
|
||||||
let first = iter.next();
|
let first = iter.next();
|
||||||
let second = iter.next();
|
let second = iter.next();
|
||||||
@ -461,9 +463,8 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
|
|||||||
} else {
|
} else {
|
||||||
self.type_error()
|
self.type_error()
|
||||||
}
|
}
|
||||||
} else {
|
},
|
||||||
self.type_error()
|
);
|
||||||
}
|
|
||||||
#[cfg(feature = "no_object")]
|
#[cfg(feature = "no_object")]
|
||||||
return self.type_error();
|
return self.type_error();
|
||||||
}
|
}
|
||||||
@ -488,7 +489,7 @@ struct IterateDynamicArray<'a, ITER: Iterator<Item = &'a Dynamic>> {
|
|||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
impl<'a, ITER: Iterator<Item = &'a Dynamic>> IterateDynamicArray<'a, ITER> {
|
impl<'a, ITER: Iterator<Item = &'a Dynamic>> IterateDynamicArray<'a, ITER> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(iter: ITER) -> Self {
|
pub const fn new(iter: ITER) -> Self {
|
||||||
Self { iter }
|
Self { iter }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,7 +526,7 @@ struct IterateMap<'a, K: Iterator<Item = &'a str>, V: Iterator<Item = &'a Dynami
|
|||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
impl<'a, K: Iterator<Item = &'a str>, V: Iterator<Item = &'a Dynamic>> IterateMap<'a, K, V> {
|
impl<'a, K: Iterator<Item = &'a str>, V: Iterator<Item = &'a Dynamic>> IterateMap<'a, K, V> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(keys: K, values: V) -> Self {
|
pub const fn new(keys: K, values: V) -> Self {
|
||||||
Self { keys, values }
|
Self { keys, values }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ impl PartialOrd for FnMetadata<'_> {
|
|||||||
|
|
||||||
impl Ord for FnMetadata<'_> {
|
impl Ord for FnMetadata<'_> {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
match self.name.cmp(&other.name) {
|
match self.name.cmp(other.name) {
|
||||||
Ordering::Equal => self.num_params.cmp(&other.num_params),
|
Ordering::Equal => self.num_params.cmp(&other.num_params),
|
||||||
cmp => cmp,
|
cmp => cmp,
|
||||||
}
|
}
|
||||||
@ -79,8 +79,8 @@ impl<'a> From<&'a FuncInfo> for FnMetadata<'a> {
|
|||||||
base_hash,
|
base_hash,
|
||||||
full_hash,
|
full_hash,
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
namespace: info.metadata.namespace.into(),
|
namespace: info.metadata.namespace,
|
||||||
access: info.metadata.access.into(),
|
access: info.metadata.access,
|
||||||
name: &info.metadata.name,
|
name: &info.metadata.name,
|
||||||
typ,
|
typ,
|
||||||
num_params: info.metadata.params,
|
num_params: info.metadata.params,
|
||||||
@ -150,7 +150,7 @@ impl<'a> From<&'a crate::Module> for ModuleMetadata<'a> {
|
|||||||
functions.sort();
|
functions.sort();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
doc: module.doc().into(),
|
doc: module.doc(),
|
||||||
modules: module
|
modules: module
|
||||||
.iter_sub_modules()
|
.iter_sub_modules()
|
||||||
.map(|(name, m)| (name, m.as_ref().into()))
|
.map(|(name, m)| (name, m.as_ref().into()))
|
||||||
@ -206,7 +206,7 @@ pub fn gen_metadata_to_json(
|
|||||||
|
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
if let Some(ast) = _ast {
|
if let Some(ast) = _ast {
|
||||||
global.doc = ast.doc().into();
|
global.doc = ast.doc();
|
||||||
}
|
}
|
||||||
|
|
||||||
serde_json::to_string_pretty(&global)
|
serde_json::to_string_pretty(&global)
|
||||||
|
@ -20,7 +20,7 @@ struct DynamicSerializer {
|
|||||||
impl DynamicSerializer {
|
impl DynamicSerializer {
|
||||||
/// Create a [`DynamicSerializer`] from a [`Dynamic`][crate::Dynamic] value.
|
/// Create a [`DynamicSerializer`] from a [`Dynamic`][crate::Dynamic] value.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(_value: Dynamic) -> Self {
|
pub const fn new(_value: Dynamic) -> Self {
|
||||||
Self {
|
Self {
|
||||||
_key: Dynamic::UNIT,
|
_key: Dynamic::UNIT,
|
||||||
_value,
|
_value,
|
||||||
|
@ -14,7 +14,7 @@ pub struct StringSliceDeserializer<'a> {
|
|||||||
impl<'a> StringSliceDeserializer<'a> {
|
impl<'a> StringSliceDeserializer<'a> {
|
||||||
/// Create an `ImmutableStringDeserializer` from an `&str` reference.
|
/// Create an `ImmutableStringDeserializer` from an `&str` reference.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn from_str(value: &'a str) -> Self {
|
pub const fn from_str(value: &'a str) -> Self {
|
||||||
Self { value }
|
Self { value }
|
||||||
}
|
}
|
||||||
/// Shortcut for a type conversion error.
|
/// Shortcut for a type conversion error.
|
||||||
|
@ -1701,11 +1701,11 @@ fn get_next_token_inner(
|
|||||||
// letter or underscore ...
|
// letter or underscore ...
|
||||||
#[cfg(not(feature = "unicode-xid-ident"))]
|
#[cfg(not(feature = "unicode-xid-ident"))]
|
||||||
('a'..='z' | '_' | 'A'..='Z', ..) => {
|
('a'..='z' | '_' | 'A'..='Z', ..) => {
|
||||||
return get_identifier(stream, pos, start_pos, c);
|
return Some(get_identifier(stream, pos, start_pos, c));
|
||||||
}
|
}
|
||||||
#[cfg(feature = "unicode-xid-ident")]
|
#[cfg(feature = "unicode-xid-ident")]
|
||||||
(ch, ..) if unicode_xid::UnicodeXID::is_xid_start(ch) || ch == '_' => {
|
(ch, ..) if unicode_xid::UnicodeXID::is_xid_start(ch) || ch == '_' => {
|
||||||
return get_identifier(stream, pos, start_pos, c);
|
return Some(get_identifier(stream, pos, start_pos, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
// " - string literal
|
// " - string literal
|
||||||
@ -2178,7 +2178,7 @@ fn get_identifier(
|
|||||||
pos: &mut Position,
|
pos: &mut Position,
|
||||||
start_pos: Position,
|
start_pos: Position,
|
||||||
first_char: char,
|
first_char: char,
|
||||||
) -> Option<(Token, Position)> {
|
) -> (Token, Position) {
|
||||||
let mut result = smallvec::SmallVec::<[char; 8]>::new();
|
let mut result = smallvec::SmallVec::<[char; 8]>::new();
|
||||||
result.push(first_char);
|
result.push(first_char);
|
||||||
|
|
||||||
@ -2197,17 +2197,17 @@ fn get_identifier(
|
|||||||
let identifier: String = result.into_iter().collect();
|
let identifier: String = result.into_iter().collect();
|
||||||
|
|
||||||
if let Some(token) = Token::lookup_from_syntax(&identifier) {
|
if let Some(token) = Token::lookup_from_syntax(&identifier) {
|
||||||
return Some((token, start_pos));
|
return (token, start_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_valid_identifier {
|
if !is_valid_identifier {
|
||||||
return Some((
|
return (
|
||||||
Token::LexError(LERR::MalformedIdentifier(identifier).into()),
|
Token::LexError(LERR::MalformedIdentifier(identifier).into()),
|
||||||
start_pos,
|
start_pos,
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some((Token::Identifier(identifier.into()), start_pos))
|
(Token::Identifier(identifier.into()), start_pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is a keyword allowed as a function?
|
/// Is a keyword allowed as a function?
|
||||||
@ -2272,7 +2272,7 @@ pub fn is_id_continue(x: char) -> bool {
|
|||||||
#[cfg(not(feature = "unicode-xid-ident"))]
|
#[cfg(not(feature = "unicode-xid-ident"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_id_first_alphabetic(x: char) -> bool {
|
pub const fn is_id_first_alphabetic(x: char) -> bool {
|
||||||
x.is_ascii_alphabetic()
|
x.is_ascii_alphabetic()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2280,7 +2280,7 @@ pub fn is_id_first_alphabetic(x: char) -> bool {
|
|||||||
#[cfg(not(feature = "unicode-xid-ident"))]
|
#[cfg(not(feature = "unicode-xid-ident"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_id_continue(x: char) -> bool {
|
pub const fn is_id_continue(x: char) -> bool {
|
||||||
x.is_ascii_alphanumeric() || x == '_'
|
x.is_ascii_alphanumeric() || x == '_'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1166,7 +1166,7 @@ impl Dynamic {
|
|||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
reify!(value, |v: crate::Blob| {
|
reify!(value, |v: crate::Blob| {
|
||||||
// don't use blob.into() because it'll be converted into an Array
|
// don't use blob.into() because it'll be converted into an Array
|
||||||
return Dynamic::from_blob(v);
|
return Self::from_blob(v);
|
||||||
});
|
});
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
reify!(value, |v: crate::Map| return v.into());
|
reify!(value, |v: crate::Map| return v.into());
|
||||||
@ -1175,7 +1175,7 @@ impl Dynamic {
|
|||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
reify!(value, |v: Instant| return v.into());
|
reify!(value, |v: Instant| return v.into());
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
reify!(value, |v: crate::Shared<crate::Locked<Dynamic>>| return v
|
reify!(value, |v: crate::Shared<crate::Locked<Self>>| return v
|
||||||
.into());
|
.into());
|
||||||
|
|
||||||
Self(Union::Variant(
|
Self(Union::Variant(
|
||||||
@ -1444,7 +1444,7 @@ impl Dynamic {
|
|||||||
let value = crate::func::locked_read(cell);
|
let value = crate::func::locked_read(cell);
|
||||||
|
|
||||||
return if (*value).type_id() != TypeId::of::<T>()
|
return if (*value).type_id() != TypeId::of::<T>()
|
||||||
&& TypeId::of::<Dynamic>() != TypeId::of::<T>()
|
&& TypeId::of::<Self>() != TypeId::of::<T>()
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -1476,7 +1476,7 @@ impl Dynamic {
|
|||||||
let guard = crate::func::locked_write(cell);
|
let guard = crate::func::locked_write(cell);
|
||||||
|
|
||||||
return if (*guard).type_id() != TypeId::of::<T>()
|
return if (*guard).type_id() != TypeId::of::<T>()
|
||||||
&& TypeId::of::<Dynamic>() != TypeId::of::<T>()
|
&& TypeId::of::<Self>() != TypeId::of::<T>()
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -1577,7 +1577,7 @@ impl Dynamic {
|
|||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if TypeId::of::<T>() == TypeId::of::<Dynamic>() {
|
if TypeId::of::<T>() == TypeId::of::<Self>() {
|
||||||
return self.as_any().downcast_ref::<T>();
|
return self.as_any().downcast_ref::<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1675,7 +1675,7 @@ impl Dynamic {
|
|||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if TypeId::of::<T>() == TypeId::of::<Dynamic>() {
|
if TypeId::of::<T>() == TypeId::of::<Self>() {
|
||||||
return self.as_any_mut().downcast_mut::<T>();
|
return self.as_any_mut().downcast_mut::<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1962,7 +1962,7 @@ impl<T: Variant + Clone> From<Vec<T>> for Dynamic {
|
|||||||
#[inline]
|
#[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(Self::from).collect()),
|
||||||
DEFAULT_TAG_VALUE,
|
DEFAULT_TAG_VALUE,
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
))
|
))
|
||||||
@ -1973,7 +1973,7 @@ impl<T: Variant + Clone> From<&[T]> for Dynamic {
|
|||||||
#[inline]
|
#[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(Self::from).collect()),
|
||||||
DEFAULT_TAG_VALUE,
|
DEFAULT_TAG_VALUE,
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
))
|
))
|
||||||
@ -1984,7 +1984,7 @@ impl<T: Variant + Clone> std::iter::FromIterator<T> for Dynamic {
|
|||||||
#[inline]
|
#[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(Self::from).collect()),
|
||||||
DEFAULT_TAG_VALUE,
|
DEFAULT_TAG_VALUE,
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
))
|
))
|
||||||
@ -2001,7 +2001,7 @@ impl<K: Into<crate::Identifier>, T: Variant + Clone> From<std::collections::Hash
|
|||||||
Box::new(
|
Box::new(
|
||||||
value
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k.into(), Dynamic::from(v)))
|
.map(|(k, v)| (k.into(), Self::from(v)))
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
DEFAULT_TAG_VALUE,
|
DEFAULT_TAG_VALUE,
|
||||||
@ -2015,12 +2015,7 @@ impl<K: Into<crate::Identifier>> From<std::collections::HashSet<K>> for Dynamic
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn from(value: std::collections::HashSet<K>) -> Self {
|
fn from(value: std::collections::HashSet<K>) -> Self {
|
||||||
Self(Union::Map(
|
Self(Union::Map(
|
||||||
Box::new(
|
Box::new(value.into_iter().map(|k| (k.into(), Self::UNIT)).collect()),
|
||||||
value
|
|
||||||
.into_iter()
|
|
||||||
.map(|k| (k.into(), Dynamic::UNIT))
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
DEFAULT_TAG_VALUE,
|
DEFAULT_TAG_VALUE,
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
))
|
))
|
||||||
@ -2036,7 +2031,7 @@ impl<K: Into<crate::Identifier>, T: Variant + Clone> From<std::collections::BTre
|
|||||||
Box::new(
|
Box::new(
|
||||||
value
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k.into(), Dynamic::from(v)))
|
.map(|(k, v)| (k.into(), Self::from(v)))
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
DEFAULT_TAG_VALUE,
|
DEFAULT_TAG_VALUE,
|
||||||
@ -2049,12 +2044,7 @@ impl<K: Into<crate::Identifier>> From<std::collections::BTreeSet<K>> for Dynamic
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn from(value: std::collections::BTreeSet<K>) -> Self {
|
fn from(value: std::collections::BTreeSet<K>) -> Self {
|
||||||
Self(Union::Map(
|
Self(Union::Map(
|
||||||
Box::new(
|
Box::new(value.into_iter().map(|k| (k.into(), Self::UNIT)).collect()),
|
||||||
value
|
|
||||||
.into_iter()
|
|
||||||
.map(|k| (k.into(), Dynamic::UNIT))
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
DEFAULT_TAG_VALUE,
|
DEFAULT_TAG_VALUE,
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
))
|
))
|
||||||
@ -2074,7 +2064,7 @@ impl From<Instant> for Dynamic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
impl From<crate::Shared<crate::Locked<Dynamic>>> for Dynamic {
|
impl From<crate::Shared<crate::Locked<Self>>> for Dynamic {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(value: crate::Shared<crate::Locked<Self>>) -> Self {
|
fn from(value: crate::Shared<crate::Locked<Self>>) -> Self {
|
||||||
Self(Union::Shared(value, DEFAULT_TAG_VALUE, ReadWrite))
|
Self(Union::Shared(value, DEFAULT_TAG_VALUE, ReadWrite))
|
||||||
@ -2084,12 +2074,12 @@ impl From<crate::Shared<crate::Locked<Dynamic>>> for Dynamic {
|
|||||||
impl From<ExclusiveRange> for Dynamic {
|
impl From<ExclusiveRange> for Dynamic {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(value: ExclusiveRange) -> Self {
|
fn from(value: ExclusiveRange) -> Self {
|
||||||
Dynamic::from(value)
|
Self::from(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<InclusiveRange> for Dynamic {
|
impl From<InclusiveRange> for Dynamic {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(value: InclusiveRange) -> Self {
|
fn from(value: InclusiveRange) -> Self {
|
||||||
Dynamic::from(value)
|
Self::from(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,9 +368,6 @@ impl EvalAltResult {
|
|||||||
map.insert("function".into(), f.into());
|
map.insert("function".into(), f.into());
|
||||||
map.insert("source".into(), s.into());
|
map.insert("source".into(), s.into());
|
||||||
}
|
}
|
||||||
Self::ErrorInModule(m, ..) => {
|
|
||||||
map.insert("module".into(), m.into());
|
|
||||||
}
|
|
||||||
Self::ErrorMismatchDataType(r, a, ..) | Self::ErrorMismatchOutputType(r, a, ..) => {
|
Self::ErrorMismatchDataType(r, a, ..) | Self::ErrorMismatchOutputType(r, a, ..) => {
|
||||||
map.insert("requested".into(), r.into());
|
map.insert("requested".into(), r.into());
|
||||||
map.insert("actual".into(), a.into());
|
map.insert("actual".into(), a.into());
|
||||||
@ -381,9 +378,6 @@ impl EvalAltResult {
|
|||||||
map.insert("length".into(), (*n as INT).into());
|
map.insert("length".into(), (*n as INT).into());
|
||||||
map.insert("index".into(), (*i as INT).into());
|
map.insert("index".into(), (*i as INT).into());
|
||||||
}
|
}
|
||||||
Self::ErrorIndexingType(t, ..) => {
|
|
||||||
map.insert("type".into(), t.into());
|
|
||||||
}
|
|
||||||
Self::ErrorVariableExists(v, ..)
|
Self::ErrorVariableExists(v, ..)
|
||||||
| Self::ErrorForbiddenVariable(v, ..)
|
| Self::ErrorForbiddenVariable(v, ..)
|
||||||
| Self::ErrorVariableNotFound(v, ..)
|
| Self::ErrorVariableNotFound(v, ..)
|
||||||
@ -395,14 +389,14 @@ impl EvalAltResult {
|
|||||||
Self::ErrorIndexNotFound(v, ..) => {
|
Self::ErrorIndexNotFound(v, ..) => {
|
||||||
map.insert("index".into(), v.clone());
|
map.insert("index".into(), v.clone());
|
||||||
}
|
}
|
||||||
Self::ErrorModuleNotFound(m, ..) => {
|
Self::ErrorInModule(m, ..) | Self::ErrorModuleNotFound(m, ..) => {
|
||||||
map.insert("module".into(), m.into());
|
map.insert("module".into(), m.into());
|
||||||
}
|
}
|
||||||
Self::ErrorDotExpr(p, ..) => {
|
Self::ErrorDotExpr(p, ..) => {
|
||||||
map.insert("property".into(), p.into());
|
map.insert("property".into(), p.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::ErrorDataTooLarge(t, ..) => {
|
Self::ErrorIndexingType(t, ..) | Self::ErrorDataTooLarge(t, ..) => {
|
||||||
map.insert("type".into(), t.into());
|
map.insert("type".into(), t.into());
|
||||||
}
|
}
|
||||||
Self::ErrorTerminated(t, ..) => {
|
Self::ErrorTerminated(t, ..) => {
|
||||||
|
@ -264,9 +264,9 @@ impl Add<ImmutableString> for &ImmutableString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddAssign<&ImmutableString> for ImmutableString {
|
impl AddAssign<&Self> for ImmutableString {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add_assign(&mut self, rhs: &ImmutableString) {
|
fn add_assign(&mut self, rhs: &Self) {
|
||||||
if !rhs.is_empty() {
|
if !rhs.is_empty() {
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
self.0 = rhs.0.clone();
|
self.0 = rhs.0.clone();
|
||||||
@ -277,9 +277,9 @@ impl AddAssign<&ImmutableString> for ImmutableString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddAssign<ImmutableString> for ImmutableString {
|
impl AddAssign<Self> for ImmutableString {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add_assign(&mut self, rhs: ImmutableString) {
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
if !rhs.is_empty() {
|
if !rhs.is_empty() {
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
self.0 = rhs.0;
|
self.0 = rhs.0;
|
||||||
@ -431,9 +431,9 @@ impl Sub for &ImmutableString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SubAssign<&ImmutableString> for ImmutableString {
|
impl SubAssign<&Self> for ImmutableString {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub_assign(&mut self, rhs: &ImmutableString) {
|
fn sub_assign(&mut self, rhs: &Self) {
|
||||||
if !rhs.is_empty() {
|
if !rhs.is_empty() {
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
self.0 = rhs.0.clone();
|
self.0 = rhs.0.clone();
|
||||||
@ -445,9 +445,9 @@ impl SubAssign<&ImmutableString> for ImmutableString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SubAssign<ImmutableString> for ImmutableString {
|
impl SubAssign<Self> for ImmutableString {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub_assign(&mut self, rhs: ImmutableString) {
|
fn sub_assign(&mut self, rhs: Self) {
|
||||||
if !rhs.is_empty() {
|
if !rhs.is_empty() {
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
self.0 = rhs.0;
|
self.0 = rhs.0;
|
||||||
|
@ -64,7 +64,7 @@ impl StringsInterner<'_> {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get<S: AsRef<str> + Into<ImmutableString>>(&mut self, text: S) -> ImmutableString {
|
pub fn get<S: AsRef<str> + Into<ImmutableString>>(&mut self, text: S) -> ImmutableString {
|
||||||
self.get_with_mapper(|s| s.into(), text)
|
self.get_with_mapper(Into::into, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an identifier from a text string, adding it to the interner if necessary.
|
/// Get an identifier from a text string, adding it to the interner if necessary.
|
||||||
|
@ -302,13 +302,13 @@ impl ParseError {
|
|||||||
/// Get the [type][ParseErrorType] of this parse error.
|
/// Get the [type][ParseErrorType] of this parse error.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn err_type(&self) -> &ParseErrorType {
|
pub const fn err_type(&self) -> &ParseErrorType {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
/// Get the [position][Position] of this parse error.
|
/// Get the [position][Position] of this parse error.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn position(&self) -> Position {
|
pub const fn position(&self) -> Position {
|
||||||
self.1
|
self.1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,7 +323,7 @@ impl From<ParseErrorType> for RhaiError {
|
|||||||
impl From<ParseErrorType> for ERR {
|
impl From<ParseErrorType> for ERR {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(err: ParseErrorType) -> Self {
|
fn from(err: ParseErrorType) -> Self {
|
||||||
ERR::ErrorParsing(err, Position::NONE)
|
Self::ErrorParsing(err, Position::NONE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,6 +337,6 @@ impl From<ParseError> for RhaiError {
|
|||||||
impl From<ParseError> for ERR {
|
impl From<ParseError> for ERR {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(err: ParseError) -> Self {
|
fn from(err: ParseError) -> Self {
|
||||||
ERR::ErrorParsing(*err.0, err.1)
|
Self::ErrorParsing(*err.0, err.1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use rhai::{CustomType, Engine, EvalAltResult, Position, TypeBuilder, INT};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_type() -> Result<(), Box<EvalAltResult>> {
|
fn build_type() -> Result<(), Box<EvalAltResult>> {
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
struct Vec3 {
|
struct Vec3 {
|
||||||
x: INT,
|
x: INT,
|
||||||
y: INT,
|
y: INT,
|
||||||
@ -60,7 +60,8 @@ fn build_type() -> Result<(), Box<EvalAltResult>> {
|
|||||||
.with_name("Vec3")
|
.with_name("Vec3")
|
||||||
.is_iterable()
|
.is_iterable()
|
||||||
.with_fn("vec3", Self::new)
|
.with_fn("vec3", Self::new)
|
||||||
.is_iterable()
|
.with_fn("==", |x: &mut Vec3, y: Vec3| *x == y)
|
||||||
|
.with_fn("!=", |x: &mut Vec3, y: Vec3| *x != y)
|
||||||
.with_get_set("x", Self::get_x, Self::set_x)
|
.with_get_set("x", Self::get_x, Self::set_x)
|
||||||
.with_get_set("y", Self::get_y, Self::set_y)
|
.with_get_set("y", Self::get_y, Self::set_y)
|
||||||
.with_get_set("z", Self::get_z, Self::set_z);
|
.with_get_set("z", Self::get_z, Self::set_z);
|
||||||
|
Loading…
Reference in New Issue
Block a user