introspect_core/struct/field/builder.rs
1use crate::r#struct::Field;
2
3/// A builder for a [`Field`].
4#[derive(Debug, Default)]
5pub struct Builder {
6 /// An identifier for the field, if it exists.
7 identifier: Option<String>,
8
9 /// The documentation for the field, if it exists.
10 documentation: Option<String>,
11}
12
13impl Builder {
14 /// Sets the identifier for this [`Builder`].
15 ///
16 /// # Examples
17 ///
18 /// ```
19 /// use introspect_core as core;
20 ///
21 /// let builder = core::r#struct::field::Builder::default()
22 /// .identifier("Name");
23 /// ```
24 pub fn identifier<S: Into<String>>(mut self, value: S) -> Self {
25 self.identifier = Some(value.into());
26 self
27 }
28
29 /// Sets the documentation for this [`Builder`].
30 ///
31 /// # Examples
32 ///
33 /// ```
34 /// use introspect_core as core;
35 ///
36 /// let builder = core::r#struct::field::Builder::default()
37 /// .documentation("Documentation.");
38 /// ```
39 pub fn documentation<S: Into<String>>(mut self, value: S) -> Self {
40 self.documentation = Some(value.into());
41 self
42 }
43
44 /// Consume `self` to produce an immutable [`Field`].
45 ///
46 /// # Examples
47 ///
48 /// ```
49 /// use introspect_core as core;
50 ///
51 /// let field = core::r#struct::field::Builder::default()
52 /// .identifier("Name")
53 /// .documentation("Documentation.")
54 /// .build();
55 /// ```
56 pub fn build(self) -> Field {
57 Field {
58 identifier: self.identifier,
59 documentation: self.documentation,
60 }
61 }
62}