Derive more standard traits.
This commit is contained in:
parent
03c64688ad
commit
ec67879759
@ -173,11 +173,8 @@ impl FunctionsLib {
|
||||
vec.into_iter()
|
||||
.map(|fn_def| {
|
||||
// Qualifiers (none) + function name + placeholders (one for each parameter).
|
||||
let hash = calc_fn_hash(
|
||||
empty(),
|
||||
&fn_def.name,
|
||||
repeat(EMPTY_TYPE_ID()).take(fn_def.params.len()),
|
||||
);
|
||||
let args_iter = repeat(EMPTY_TYPE_ID()).take(fn_def.params.len());
|
||||
let hash = calc_fn_hash(empty(), &fn_def.name, args_iter);
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
{
|
||||
@ -284,11 +281,9 @@ pub struct Engine {
|
||||
pub(crate) packages: PackagesCollection,
|
||||
/// A collection of all library packages loaded into the engine.
|
||||
pub(crate) base_package: PackageStore,
|
||||
|
||||
/// A module resolution service.
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
pub(crate) module_resolver: Option<Box<dyn ModuleResolver>>,
|
||||
|
||||
/// A hashmap mapping type names to pretty-print names.
|
||||
pub(crate) type_names: HashMap<String, String>,
|
||||
|
||||
@ -299,7 +294,6 @@ pub struct Engine {
|
||||
|
||||
/// Optimize the AST after compilation.
|
||||
pub(crate) optimization_level: OptimizationLevel,
|
||||
|
||||
/// Maximum levels of call-stack to prevent infinite recursion.
|
||||
///
|
||||
/// Defaults to 28 for debug builds and 256 for non-debug builds.
|
||||
|
@ -122,7 +122,7 @@ impl ParseErrorType {
|
||||
}
|
||||
|
||||
/// Error when parsing a script.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
|
||||
pub struct ParseError(pub(crate) ParseErrorType, pub(crate) Position);
|
||||
|
||||
impl ParseError {
|
||||
|
@ -70,7 +70,7 @@ pub trait IteratorCallback: Fn(Dynamic) -> Box<dyn Iterator<Item = Dynamic>> + '
|
||||
impl<F: Fn(Dynamic) -> Box<dyn Iterator<Item = Dynamic>> + 'static> IteratorCallback for F {}
|
||||
|
||||
/// A type representing the type of ABI of a native Rust function.
|
||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)]
|
||||
pub enum NativeFunctionABI {
|
||||
/// A pure function where all arguments are passed by value.
|
||||
Pure,
|
||||
|
@ -757,7 +757,7 @@ mod file {
|
||||
/// let mut engine = Engine::new();
|
||||
/// engine.set_module_resolver(Some(resolver));
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, Eq, PartialEq, PartialOrd, Ord, Clone, Hash)]
|
||||
pub struct FileModuleResolver {
|
||||
path: PathBuf,
|
||||
extension: String,
|
||||
@ -875,7 +875,7 @@ mod file {
|
||||
///
|
||||
/// A `StaticVec` is used because most module-level access contains only one level,
|
||||
/// and it is wasteful to always allocate a `Vec` with one element.
|
||||
#[derive(Clone, Hash, Default)]
|
||||
#[derive(Clone, Eq, PartialEq, Hash, Default)]
|
||||
pub struct ModuleRef(StaticVec<(String, Position)>, Option<NonZeroUsize>);
|
||||
|
||||
impl fmt::Debug for ModuleRef {
|
||||
|
@ -13,7 +13,7 @@ use crate::utils::EMPTY_TYPE_ID;
|
||||
use crate::module::ModuleRef;
|
||||
|
||||
#[cfg(feature = "no_module")]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Hash, Copy, Default)]
|
||||
pub struct ModuleRef;
|
||||
|
||||
use crate::stdlib::{
|
||||
@ -179,7 +179,7 @@ impl Add<Self> for &AST {
|
||||
}
|
||||
|
||||
/// A type representing the access mode of a scripted function.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||
pub enum FnAccess {
|
||||
/// Private function.
|
||||
Private,
|
||||
@ -210,7 +210,7 @@ pub type SharedFnDef = Arc<FnDef>;
|
||||
pub type SharedFnDef = Rc<FnDef>;
|
||||
|
||||
/// `return`/`throw` statement.
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
|
||||
pub enum ReturnType {
|
||||
/// `return` statement.
|
||||
Return,
|
||||
|
@ -22,7 +22,7 @@ pub enum EntryType {
|
||||
}
|
||||
|
||||
/// An entry in the Scope.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Entry<'a> {
|
||||
/// Name of the entry.
|
||||
pub name: Cow<'a, str>,
|
||||
@ -64,7 +64,7 @@ pub struct Entry<'a> {
|
||||
/// allowing for automatic _shadowing_.
|
||||
///
|
||||
/// Currently, `Scope` is neither `Send` nor `Sync`. Turn on the `sync` feature to make it `Send + Sync`.
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Scope<'a>(Vec<Entry<'a>>);
|
||||
|
||||
impl<'a> Scope<'a> {
|
||||
|
@ -64,6 +64,14 @@ pub struct StaticVec<T> {
|
||||
more: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T: PartialEq> PartialEq for StaticVec<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.len == other.len && self.list == other.list && self.more == other.more
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Eq> Eq for StaticVec<T> {}
|
||||
|
||||
impl<T> Default for StaticVec<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
Loading…
Reference in New Issue
Block a user