Add #[must_use]
This commit is contained in:
@@ -41,6 +41,7 @@ impl ModuleResolversCollection {
|
||||
/// engine.set_module_resolver(collection);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
@@ -76,11 +77,13 @@ impl ModuleResolversCollection {
|
||||
}
|
||||
/// Get an iterator of all the [module resolvers][ModuleResolver].
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn iter(&self) -> impl Iterator<Item = &dyn ModuleResolver> {
|
||||
self.0.iter().map(|v| v.as_ref())
|
||||
}
|
||||
/// Get a mutable iterator of all the [module resolvers][ModuleResolver].
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn into_iter(self) -> impl Iterator<Item = Box<dyn ModuleResolver>> {
|
||||
self.0.into_iter()
|
||||
}
|
||||
@@ -92,11 +95,13 @@ impl ModuleResolversCollection {
|
||||
}
|
||||
/// Is this [`ModuleResolversCollection`] empty?
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
/// Get the number of [module resolvers][ModuleResolver] in this [`ModuleResolversCollection`].
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
@@ -77,6 +77,7 @@ impl FileModuleResolver {
|
||||
/// engine.set_module_resolver(resolver);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self::new_with_extension(RHAI_SCRIPT_EXTENSION)
|
||||
}
|
||||
@@ -99,6 +100,7 @@ impl FileModuleResolver {
|
||||
/// engine.set_module_resolver(resolver);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn new_with_path(path: impl Into<PathBuf>) -> Self {
|
||||
Self::new_with_path_and_extension(path, RHAI_SCRIPT_EXTENSION)
|
||||
}
|
||||
@@ -118,6 +120,7 @@ impl FileModuleResolver {
|
||||
/// engine.set_module_resolver(resolver);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn new_with_extension(extension: impl Into<Identifier>) -> Self {
|
||||
Self {
|
||||
base_path: None,
|
||||
@@ -143,6 +146,7 @@ impl FileModuleResolver {
|
||||
/// engine.set_module_resolver(resolver);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn new_with_path_and_extension(
|
||||
path: impl Into<PathBuf>,
|
||||
extension: impl Into<Identifier>,
|
||||
@@ -157,6 +161,7 @@ impl FileModuleResolver {
|
||||
|
||||
/// Get the base path for script files.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn base_path(&self) -> Option<&Path> {
|
||||
self.base_path.as_ref().map(PathBuf::as_ref)
|
||||
}
|
||||
@@ -169,6 +174,7 @@ impl FileModuleResolver {
|
||||
|
||||
/// Get the script file extension.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn extension(&self) -> &str {
|
||||
&self.extension
|
||||
}
|
||||
@@ -188,12 +194,14 @@ impl FileModuleResolver {
|
||||
}
|
||||
/// Is the cache enabled?
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn is_cache_enabled(&self) -> bool {
|
||||
self.cache_enabled
|
||||
}
|
||||
|
||||
/// Is a particular path cached?
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn is_cached(&self, path: &str, source_path: Option<&str>) -> bool {
|
||||
if !self.cache_enabled {
|
||||
return false;
|
||||
@@ -208,16 +216,19 @@ impl FileModuleResolver {
|
||||
}
|
||||
/// Empty the internal cache.
|
||||
#[inline(always)]
|
||||
pub fn clear_cache(&mut self) {
|
||||
pub fn clear_cache(&mut self) -> &mut Self {
|
||||
#[cfg(not(feature = "sync"))]
|
||||
self.cache.borrow_mut().clear();
|
||||
#[cfg(feature = "sync")]
|
||||
self.cache.write().unwrap().clear();
|
||||
|
||||
self
|
||||
}
|
||||
/// Remove the specified path from internal cache.
|
||||
///
|
||||
/// The next time this path is resolved, the script file will be loaded once again.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn clear_cache_for_path(
|
||||
&mut self,
|
||||
path: &str,
|
||||
@@ -240,6 +251,8 @@ impl FileModuleResolver {
|
||||
.map(|(_, v)| v);
|
||||
}
|
||||
/// Construct a full file path.
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
fn get_file_path(&self, path: &str, source_path: Option<&str>) -> PathBuf {
|
||||
let path = Path::new(path);
|
||||
|
||||
|
@@ -23,6 +23,7 @@ pub use stat::StaticModuleResolver;
|
||||
/// Trait that encapsulates a module resolution service.
|
||||
pub trait ModuleResolver: SendSync {
|
||||
/// Resolve a module based on a path string.
|
||||
#[must_use]
|
||||
fn resolve(
|
||||
&self,
|
||||
engine: &Engine,
|
||||
@@ -41,6 +42,7 @@ pub trait ModuleResolver: SendSync {
|
||||
/// Override the default implementation of this method if the module resolver
|
||||
/// serves modules based on compiled Rhai scripts.
|
||||
#[allow(unused_variables)]
|
||||
#[must_use]
|
||||
fn resolve_ast(
|
||||
&self,
|
||||
engine: &Engine,
|
||||
|
@@ -41,6 +41,7 @@ impl StaticModuleResolver {
|
||||
/// engine.set_module_resolver(resolver);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
@@ -57,38 +58,45 @@ impl StaticModuleResolver {
|
||||
}
|
||||
/// Does the path exist?
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn contains_path(&self, path: &str) -> bool {
|
||||
self.0.contains_key(path)
|
||||
}
|
||||
/// Get an iterator of all the [modules][Module].
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
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][Module].
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)> {
|
||||
self.0.iter_mut().map(|(k, v)| (k.as_str(), v))
|
||||
}
|
||||
/// Get a mutable iterator of all the modules.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn into_iter(self) -> impl Iterator<Item = (Identifier, Shared<Module>)> {
|
||||
self.0.into_iter()
|
||||
}
|
||||
/// Get an iterator of all the [module][Module] paths.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn paths(&self) -> impl Iterator<Item = &str> {
|
||||
self.0.keys().map(|s| s.as_str())
|
||||
}
|
||||
/// Get an iterator of all the [modules][Module].
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn values(&self) -> impl Iterator<Item = &Shared<Module>> {
|
||||
self.0.values().map(|m| m)
|
||||
}
|
||||
/// Remove all [modules][Module].
|
||||
#[inline(always)]
|
||||
pub fn clear(&mut self) {
|
||||
pub fn clear(&mut self) -> &mut Self {
|
||||
self.0.clear();
|
||||
self
|
||||
}
|
||||
/// Is this [`StaticModuleResolver`] empty?
|
||||
#[inline(always)]
|
||||
@@ -97,6 +105,7 @@ impl StaticModuleResolver {
|
||||
}
|
||||
/// Get the number of [modules][Module] in this [`StaticModuleResolver`].
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
@@ -105,10 +114,11 @@ impl StaticModuleResolver {
|
||||
///
|
||||
/// Existing modules of the same path name are overwritten.
|
||||
#[inline(always)]
|
||||
pub fn merge(&mut self, other: Self) {
|
||||
pub fn merge(&mut self, other: Self) -> &mut Self {
|
||||
if !other.is_empty() {
|
||||
self.0.extend(other.0.into_iter());
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user