Simplify code.

This commit is contained in:
Stephen Chung
2020-10-01 23:31:27 +08:00
parent a13fcc5cc2
commit e8d5f78f88
5 changed files with 104 additions and 89 deletions

View File

@@ -301,8 +301,8 @@ impl AST {
/// Iterate through all functions
#[cfg(not(feature = "no_function"))]
pub fn iter_functions(&self, action: impl FnMut(FnAccess, &str, usize)) {
self.1.iter_script_fn_info(action);
pub fn iter_functions(&self) -> impl Iterator<Item = (FnAccess, &str, usize)> {
self.1.iter_script_fn_info()
}
/// Clear all function definitions in the `AST`.
@@ -340,10 +340,10 @@ impl AsRef<Module> for AST {
/// A type representing the access mode of a scripted function.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum FnAccess {
/// Private function.
Private,
/// Public function.
Public,
/// Private function.
Private,
}
impl fmt::Display for FnAccess {
@@ -355,6 +355,23 @@ impl fmt::Display for FnAccess {
}
}
impl FnAccess {
/// Is this access mode private?
pub fn is_private(self) -> bool {
match self {
Self::Public => false,
Self::Private => true,
}
}
/// Is this access mode public?
pub fn is_public(self) -> bool {
match self {
Self::Public => true,
Self::Private => false,
}
}
}
/// [INTERNALS] A type containing information on a scripted function.
/// Exported under the `internals` feature only.
///