Refine docs and comments etc.

This commit is contained in:
Stephen Chung
2021-01-02 23:30:10 +08:00
parent 5a3bbaa322
commit ef48f47b74
22 changed files with 352 additions and 296 deletions

View File

@@ -1,7 +1,7 @@
use crate::stdlib::{boxed::Box, ops::AddAssign, vec::Vec};
use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared};
/// Module resolution service that holds a collection of module resolves,
/// [Module] resolution service that holds a collection of [module][Module] resolves,
/// to be searched in sequential order.
///
/// # Example
@@ -42,13 +42,13 @@ impl ModuleResolversCollection {
pub fn new() -> Self {
Default::default()
}
/// Append a module resolver to the end.
/// Append a [module resolver][ModuleResolver] to the end.
#[inline(always)]
pub fn push(&mut self, resolver: impl ModuleResolver + 'static) -> &mut Self {
self.0.push(Box::new(resolver));
self
}
/// Insert a module resolver to an offset index.
/// Insert a [module resolver][ModuleResolver] to an offset index.
///
/// # Panics
///
@@ -58,12 +58,12 @@ impl ModuleResolversCollection {
self.0.insert(index, Box::new(resolver));
self
}
/// Remove the last module resolver from the end, if any.
/// Remove the last [module resolver][ModuleResolver] from the end, if any.
#[inline(always)]
pub fn pop(&mut self) -> Option<Box<dyn ModuleResolver>> {
self.0.pop()
}
/// Remove a module resolver at an offset index.
/// Remove a [module resolver][ModuleResolver] at an offset index.
///
/// # Panics
///
@@ -72,17 +72,17 @@ impl ModuleResolversCollection {
pub fn remove(&mut self, index: usize) -> Box<dyn ModuleResolver> {
self.0.remove(index)
}
/// Get an iterator of all the module resolvers.
/// Get an iterator of all the [module resolvers][ModuleResolver].
#[inline(always)]
pub fn iter(&self) -> impl Iterator<Item = &dyn ModuleResolver> {
self.0.iter().map(|v| v.as_ref())
}
/// Get a mutable iterator of all the modules.
/// Get a mutable iterator of all the [module resolvers][ModuleResolver].
#[inline(always)]
pub fn into_iter(self) -> impl Iterator<Item = Box<dyn ModuleResolver>> {
self.0.into_iter()
}
/// Remove all module resolvers.
/// Remove all [module resolvers][ModuleResolver].
#[inline(always)]
pub fn clear(&mut self) -> &mut Self {
self.0.clear();
@@ -93,7 +93,7 @@ impl ModuleResolversCollection {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
/// Get the number of module resolvers in this [`ModuleResolversCollection`].
/// Get the number of [module resolvers][ModuleResolver] in this [`ModuleResolversCollection`].
#[inline(always)]
pub fn len(&self) -> usize {
self.0.len()

View File

@@ -1,7 +1,7 @@
use crate::stdlib::boxed::Box;
use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared};
/// Empty/disabled module resolution service that acts as a dummy.
/// Empty/disabled [module][Module] resolution service that acts as a dummy.
///
/// # Example
///

View File

@@ -7,21 +7,15 @@ use crate::stdlib::{
};
use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared};
/// Module resolution service that loads module script files from the file system.
/// [Module] resolution service that loads [module][Module] script files from the file system.
///
/// Script files are cached so they are are not reloaded and recompiled in subsequent requests.
///
/// The [`new_with_path`][FileModuleResolver::new_with_path] and
/// [`new_with_path_and_extension`][FileModuleResolver::new_with_path_and_extension] constructor functions
/// allow specification of a base directory with module path used as a relative path offset
/// to the base directory. The script file is then forced to be in a specified extension
/// (default `.rhai`).
///
/// # Function Namespace
///
/// When a function within a script file module is loaded, all functions in the _global_ namespace
/// When a function within a script file module is called, all functions in the _global_ namespace
/// plus all those defined within the same module are _merged_ into a _unified_ namespace before
/// the call. Therefore, functions in a module script can cross-call each other.
/// the call. Therefore, functions in a module script can always cross-call each other.
///
/// # Example
///
@@ -58,6 +52,8 @@ impl Default for FileModuleResolver {
impl FileModuleResolver {
/// Create a new [`FileModuleResolver`] with a specific base path.
///
/// The default extension is `.rhai`.
///
/// # Example
///
/// ```
@@ -78,8 +74,6 @@ impl FileModuleResolver {
/// Create a new [`FileModuleResolver`] with a specific base path and file extension.
///
/// The default extension is `.rhai`.
///
/// # Example
///
/// ```
@@ -107,6 +101,8 @@ impl FileModuleResolver {
/// Create a new [`FileModuleResolver`] with the current directory as base path.
///
/// The default extension is `.rhai`.
///
/// # Example
///
/// ```
@@ -159,7 +155,9 @@ impl FileModuleResolver {
self.cache.write().unwrap().clear();
}
/// Empty the internal cache.
/// Remove the specified path from internal cache.
///
/// The next time this path is resolved, the script file will be loaded once again.
#[inline(always)]
pub fn clear_cache_for_path(&mut self, path: impl AsRef<Path>) -> Option<Shared<Module>> {
#[cfg(not(feature = "sync"))]

View File

@@ -1,7 +1,7 @@
use crate::stdlib::{boxed::Box, collections::HashMap, ops::AddAssign, string::String};
use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared};
/// Module resolution service that serves modules added into it.
/// [Module] resolution service that serves [modules][Module] added into it.
///
/// # Example
///
@@ -42,13 +42,13 @@ impl StaticModuleResolver {
pub fn new() -> Self {
Default::default()
}
/// Add a module keyed by its path.
/// Add a [module][Module] keyed by its path.
#[inline(always)]
pub fn insert(&mut self, path: impl Into<String>, mut module: Module) {
module.build_index();
self.0.insert(path.into(), module.into());
}
/// Remove a module given its path.
/// Remove a [module][Module] given its path.
#[inline(always)]
pub fn remove(&mut self, path: &str) -> Option<Shared<Module>> {
self.0.remove(path)
@@ -58,12 +58,12 @@ impl StaticModuleResolver {
pub fn contains_path(&self, path: &str) -> bool {
self.0.contains_key(path)
}
/// Get an iterator of all the modules.
/// Get an iterator of all the [modules][Module].
#[inline(always)]
pub fn iter(&self) -> impl Iterator<Item = (&str, &Shared<Module>)> {
self.0.iter().map(|(k, v)| (k.as_str(), v))
}
/// Get a mutable iterator of all the modules.
/// Get a mutable iterator of all the [modules][Module].
#[inline(always)]
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)> {
self.0.iter_mut().map(|(k, v)| (k.as_str(), v))
@@ -73,17 +73,17 @@ impl StaticModuleResolver {
pub fn into_iter(self) -> impl Iterator<Item = (String, Shared<Module>)> {
self.0.into_iter()
}
/// Get an iterator of all the module paths.
/// Get an iterator of all the [module][Module] paths.
#[inline(always)]
pub fn paths(&self) -> impl Iterator<Item = &str> {
self.0.keys().map(String::as_str)
}
/// Get an iterator of all the modules.
/// Get an iterator of all the [modules][Module].
#[inline(always)]
pub fn values(&self) -> impl Iterator<Item = &Shared<Module>> {
self.0.values().map(|m| m)
}
/// Remove all modules.
/// Remove all [modules][Module].
#[inline(always)]
pub fn clear(&mut self) {
self.0.clear();
@@ -93,7 +93,7 @@ impl StaticModuleResolver {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
/// Get the number of modules in this [`StaticModuleResolver`].
/// Get the number of [modules][Module] in this [`StaticModuleResolver`].
#[inline(always)]
pub fn len(&self) -> usize {
self.0.len()