Derive more standard traits.

This commit is contained in:
Stephen Chung 2020-05-12 18:48:25 +08:00
parent 03c64688ad
commit ec67879759
7 changed files with 19 additions and 17 deletions

View File

@ -173,11 +173,8 @@ impl FunctionsLib {
vec.into_iter() vec.into_iter()
.map(|fn_def| { .map(|fn_def| {
// Qualifiers (none) + function name + placeholders (one for each parameter). // Qualifiers (none) + function name + placeholders (one for each parameter).
let hash = calc_fn_hash( let args_iter = repeat(EMPTY_TYPE_ID()).take(fn_def.params.len());
empty(), let hash = calc_fn_hash(empty(), &fn_def.name, args_iter);
&fn_def.name,
repeat(EMPTY_TYPE_ID()).take(fn_def.params.len()),
);
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
{ {
@ -284,11 +281,9 @@ pub struct Engine {
pub(crate) packages: PackagesCollection, pub(crate) packages: PackagesCollection,
/// A collection of all library packages loaded into the engine. /// A collection of all library packages loaded into the engine.
pub(crate) base_package: PackageStore, pub(crate) base_package: PackageStore,
/// A module resolution service. /// A module resolution service.
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
pub(crate) module_resolver: Option<Box<dyn ModuleResolver>>, pub(crate) module_resolver: Option<Box<dyn ModuleResolver>>,
/// A hashmap mapping type names to pretty-print names. /// A hashmap mapping type names to pretty-print names.
pub(crate) type_names: HashMap<String, String>, pub(crate) type_names: HashMap<String, String>,
@ -299,7 +294,6 @@ pub struct Engine {
/// Optimize the AST after compilation. /// Optimize the AST after compilation.
pub(crate) optimization_level: OptimizationLevel, pub(crate) optimization_level: OptimizationLevel,
/// Maximum levels of call-stack to prevent infinite recursion. /// Maximum levels of call-stack to prevent infinite recursion.
/// ///
/// Defaults to 28 for debug builds and 256 for non-debug builds. /// Defaults to 28 for debug builds and 256 for non-debug builds.

View File

@ -122,7 +122,7 @@ impl ParseErrorType {
} }
/// Error when parsing a script. /// 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); pub struct ParseError(pub(crate) ParseErrorType, pub(crate) Position);
impl ParseError { impl ParseError {

View File

@ -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 {} 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. /// 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 { pub enum NativeFunctionABI {
/// A pure function where all arguments are passed by value. /// A pure function where all arguments are passed by value.
Pure, Pure,

View File

@ -757,7 +757,7 @@ mod file {
/// let mut engine = Engine::new(); /// let mut engine = Engine::new();
/// engine.set_module_resolver(Some(resolver)); /// 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 { pub struct FileModuleResolver {
path: PathBuf, path: PathBuf,
extension: String, extension: String,
@ -875,7 +875,7 @@ mod file {
/// ///
/// A `StaticVec` is used because most module-level access contains only one level, /// 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. /// 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>); pub struct ModuleRef(StaticVec<(String, Position)>, Option<NonZeroUsize>);
impl fmt::Debug for ModuleRef { impl fmt::Debug for ModuleRef {

View File

@ -13,7 +13,7 @@ use crate::utils::EMPTY_TYPE_ID;
use crate::module::ModuleRef; use crate::module::ModuleRef;
#[cfg(feature = "no_module")] #[cfg(feature = "no_module")]
#[derive(Debug, Clone, Copy)] #[derive(Debug, Eq, PartialEq, Clone, Hash, Copy, Default)]
pub struct ModuleRef; pub struct ModuleRef;
use crate::stdlib::{ use crate::stdlib::{
@ -179,7 +179,7 @@ impl Add<Self> for &AST {
} }
/// A type representing the access mode of a scripted function. /// 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 { pub enum FnAccess {
/// Private function. /// Private function.
Private, Private,
@ -210,7 +210,7 @@ pub type SharedFnDef = Arc<FnDef>;
pub type SharedFnDef = Rc<FnDef>; pub type SharedFnDef = Rc<FnDef>;
/// `return`/`throw` statement. /// `return`/`throw` statement.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] #[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
pub enum ReturnType { pub enum ReturnType {
/// `return` statement. /// `return` statement.
Return, Return,

View File

@ -22,7 +22,7 @@ pub enum EntryType {
} }
/// An entry in the Scope. /// An entry in the Scope.
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Entry<'a> { pub struct Entry<'a> {
/// Name of the entry. /// Name of the entry.
pub name: Cow<'a, str>, pub name: Cow<'a, str>,
@ -64,7 +64,7 @@ pub struct Entry<'a> {
/// allowing for automatic _shadowing_. /// allowing for automatic _shadowing_.
/// ///
/// Currently, `Scope` is neither `Send` nor `Sync`. Turn on the `sync` feature to make it `Send + Sync`. /// 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>>); pub struct Scope<'a>(Vec<Entry<'a>>);
impl<'a> Scope<'a> { impl<'a> Scope<'a> {

View File

@ -64,6 +64,14 @@ pub struct StaticVec<T> {
more: Vec<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> { impl<T> Default for StaticVec<T> {
fn default() -> Self { fn default() -> Self {
Self { Self {