code_gen/rust/function/
signature_dec.rs1use crate::rust::CommentType::OuterLineDoc;
2use crate::rust::{Signature, WithComments, WithSignature};
3use crate::{CodeBuffer, Statement};
4
5pub struct SignatureDec {
7 comments: Vec<String>,
8 signature: Signature,
9}
10
11impl<S: Into<Signature>> From<S> for SignatureDec {
12 fn from(signature: S) -> Self {
13 Self {
14 comments: Vec::default(),
15 signature: signature.into(),
16 }
17 }
18}
19
20impl WithComments for SignatureDec {
21 fn comments(&self) -> &[String] {
22 self.comments.as_slice()
23 }
24
25 fn add_comment<S>(&mut self, comment: S)
26 where
27 S: Into<String>,
28 {
29 self.comments.push(comment.into());
30 }
31}
32
33impl WithSignature for SignatureDec {
34 fn signature(&self) -> &Signature {
35 &self.signature
36 }
37}
38
39impl Statement for SignatureDec {
40 fn write(&self, b: &mut CodeBuffer, level: usize) {
41 self.write_comments(OuterLineDoc, b, level);
42 b.indent(level);
43 b.write("fn ");
44 self.write_signature(b);
45 b.write(";");
46 b.end_line();
47 }
48}