codegen_rs/
field.rs

1use crate::r#type::Type;
2
3/// Defines a struct field.
4#[derive(Debug, Clone)]
5pub struct Field {
6    /// Field name
7    pub name: String,
8
9    /// Field type
10    pub ty: Type,
11
12    /// Field documentation
13    pub documentation: Vec<String>,
14
15    /// Field annotation
16    pub annotation: Vec<String>,
17}
18
19impl Field {
20    /// Return a field definition with the provided name and type
21    pub fn new<T>(name: &str, ty: T) -> Self
22    where
23        T: Into<Type>,
24    {
25        Self {
26            name: name.into(),
27            ty: ty.into(),
28            documentation: Vec::new(),
29            annotation: Vec::new(),
30        }
31    }
32
33    /// Set field's documentation.
34    pub fn doc(&mut self, documentation: Vec<&str>) -> &mut Self {
35        self.documentation = documentation.iter().map(|doc| doc.to_string()).collect();
36        self
37    }
38
39    /// Set field's annotation.
40    pub fn annotation(&mut self, annotation: Vec<&str>) -> &mut Self {
41        self.annotation = annotation.iter().map(|ann| ann.to_string()).collect();
42        self
43    }
44}