code_gen/rust/function/
with_result.rs1use crate::rust::RustType;
2use crate::{CodeBuffer, Expression};
3
4pub trait WithResult: Sized {
6 fn result(&self) -> Option<&RustType>;
8
9 fn set_result<T>(&mut self, result: T)
11 where
12 T: Into<RustType>;
13
14 fn with_result<T>(mut self, result: T) -> Self
16 where
17 T: Into<RustType>,
18 {
19 self.set_result(result);
20 self
21 }
22
23 fn write_result(&self, b: &mut CodeBuffer) {
25 if let Some(result) = self.result() {
26 b.write(" -> ");
27 result.write(b);
28 }
29 }
30}