1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use inkwell::module::Module;
use inkwell::values::FunctionValue;
pub struct FunctionIterator<'a, 'ctx> {
module: &'a Module<'ctx>,
func: Option<FunctionValue<'ctx>>,
}
impl<'a, 'ctx> FunctionIterator<'a, 'ctx> {
pub fn new(module: &'a Module<'ctx>) -> Self {
Self { module, func: None }
}
}
impl<'a, 'ctx> Iterator for FunctionIterator<'a, 'ctx> {
type Item = FunctionValue<'ctx>;
fn next(&mut self) -> Option<Self::Item> {
if let Some(func) = self.func {
self.func = func.get_next_function();
return self.func;
}
self.func = Some(self.module.get_first_function()?);
self.func
}
}