code_gen/rust/function/
with_functions.rs1use crate::rust::Function;
2use crate::{CodeBuffer, Statement};
3
4pub trait WithFunctions: Sized {
6 fn functions(&self) -> &[Function];
8
9 fn add_function<F>(&mut self, function: F)
11 where
12 F: Into<Function>;
13
14 fn with_function<F>(mut self, function: F) -> Self
16 where
17 F: Into<Function>,
18 {
19 self.add_function(function);
20 self
21 }
22
23 fn write_functions(&self, b: &mut CodeBuffer, level: usize) {
25 if let Some((first, rest)) = self.functions().split_first() {
26 first.write(b, level);
27 for function in rest {
28 b.end_line();
29 function.write(b, level);
30 }
31 }
32 }
33}