1mod field_type;
6pub use field_type::*;
7pub use typesense_codegen::models::{Field, FieldEmbed};
8
9#[derive(Debug, Default)]
11pub struct FieldBuilder {
12 name: String,
13 typesense_type: FieldType,
14 optional: Option<bool>,
15 facet: Option<bool>,
16 index: Option<bool>,
17 locale: Option<String>,
18 sort: Option<bool>,
19 infix: Option<bool>,
20 num_dim: Option<i32>,
21 drop: Option<bool>,
22 embed: Option<Box<FieldEmbed>>,
23}
24
25impl FieldBuilder {
26 #[inline]
28 pub fn new(name: impl Into<String>, typesense_type: FieldType) -> Self {
29 Self {
30 name: name.into(),
31 typesense_type,
32 ..Default::default()
33 }
34 }
35
36 #[inline]
38 pub fn optional(mut self, optional: Option<bool>) -> Self {
39 self.optional = optional;
40 self
41 }
42
43 #[inline]
45 pub fn facet(mut self, facet: Option<bool>) -> Self {
46 self.facet = facet;
47 self
48 }
49
50 #[inline]
52 pub fn index(mut self, index: Option<bool>) -> Self {
53 self.index = index;
54 self
55 }
56
57 #[inline]
59 pub fn locale(mut self, locale: Option<String>) -> Self {
60 self.locale = locale;
61 self
62 }
63
64 #[inline]
66 pub fn sort(mut self, sort: Option<bool>) -> Self {
67 self.sort = sort;
68 self
69 }
70
71 #[inline]
73 pub fn infix(mut self, infix: Option<bool>) -> Self {
74 self.infix = infix;
75 self
76 }
77
78 #[inline]
80 pub fn num_dim(mut self, num_dim: Option<i32>) -> Self {
81 self.num_dim = num_dim;
82 self
83 }
84
85 #[inline]
87 pub fn drop(mut self, drop: Option<bool>) -> Self {
88 self.drop = drop;
89 self
90 }
91
92 #[inline]
95 pub fn build(self) -> Field {
96 Field {
97 name: self.name,
98 r#type: self.typesense_type,
99 optional: self.optional,
100 facet: self.facet,
101 index: self.index,
102 locale: self.locale,
103 sort: self.sort,
104 infix: self.infix,
105 num_dim: self.num_dim,
106 drop: self.drop,
107 embed: self.embed,
108 }
109 }
110}