1use crate::function::Function;
2use crate::internal::environment::ProtoEnvironment;
3use crate::internal::module::ProtoModule;
4use crate::{Attribute, Path};
5use alloc::vec::Vec;
6
7#[derive(Debug, Clone, Copy)]
8pub struct Module {
9 pub(crate) environment: &'static ProtoEnvironment,
10 pub(crate) proto_module: &'static ProtoModule,
11}
12
13impl Module {
14 pub const fn name(&self) -> &'static str {
15 self.proto_module.name
16 }
17
18 pub const fn path(&self) -> &Path {
19 &self.proto_module.path
20 }
21
22 pub fn find_functions_such_that(&self, f: impl Fn(&Function) -> bool) -> Vec<Function> {
23 self.functions().filter(|function| f(function)).collect()
24 }
25
26 pub fn find_modules_such_that(&self, f: impl Fn(&Module) -> bool) -> Vec<Module> {
27 self.modules().filter(|function| f(function)).collect()
28 }
29
30 pub fn find_attributes_such_that(
31 &self,
32 f: impl Fn(&Attribute) -> bool,
33 ) -> Vec<&'static Attribute> {
34 self.attributes()
35 .into_iter()
36 .filter(|attribute| f(attribute))
37 .collect()
38 }
39
40 pub fn has_attribute_such_that(&self, f: impl Fn(&Attribute) -> bool) -> bool {
41 self.attributes().into_iter().any(f)
42 }
43}