Refactor code base and split into more module files.

This commit is contained in:
Stephen Chung
2020-05-05 12:24:13 +08:00
parent 143861747d
commit c03b162b7e
8 changed files with 186 additions and 143 deletions

35
src/module.rs Normal file
View File

@@ -0,0 +1,35 @@
//! Module defining external-loaded modules for Rhai.
use crate::any::Dynamic;
use crate::stdlib::{
collections::HashMap,
ops::{Deref, DerefMut},
string::String,
};
/// An imported module.
///
/// Not available under the `no_module` feature.
#[derive(Debug, Clone)]
pub struct Module(HashMap<String, Dynamic>);
impl Module {
/// Create a new module.
pub fn new() -> Self {
Self(HashMap::new())
}
}
impl Deref for Module {
type Target = HashMap<String, Dynamic>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for Module {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}