qdrant_client/builders/
formula_builder.rs1use std::collections::HashMap;
2
3use crate::qdrant::*;
4
5#[must_use]
9#[derive(Clone)]
10pub struct FormulaBuilder {
11 pub(crate) expression: Expression,
13 pub(crate) defaults: HashMap<String, Value>,
15}
16
17impl FormulaBuilder {
18 pub fn new<E: Into<Expression>>(expression: E) -> Self {
20 Self {
21 expression: expression.into(),
22 defaults: Default::default(),
23 }
24 }
25
26 pub fn expression<E: Into<Expression>>(self, value: E) -> Self {
27 let mut new = self;
28 new.expression = value.into();
29 new
30 }
31
32 pub fn defaults(mut self, defaults: HashMap<String, Value>) -> Self {
34 self.defaults = defaults;
35 self
36 }
37
38 pub fn add_default<K: Into<String>, V: Into<Value>>(self, key: K, value: V) -> Self {
40 let mut new = self;
41 new.defaults.insert(key.into(), value.into());
42 new
43 }
44
45 fn build_inner(self) -> Result<Formula, std::convert::Infallible> {
46 Ok(Formula {
47 expression: Some(self.expression),
48 defaults: self.defaults,
49 })
50 }
51}
52
53impl From<FormulaBuilder> for Formula {
54 fn from(value: FormulaBuilder) -> Self {
55 value
56 .build_inner()
57 .unwrap_or_else(|_| panic!("Failed to convert {0} to {1}", "FormulaBuilder", "Formula"))
58 }
59}
60
61impl FormulaBuilder {
62 pub fn build(self) -> Formula {
64 self.build_inner()
65 .unwrap_or_else(|_| panic!("Failed to build {0} into {1}", "FormulaBuilder", "Formula"))
66 }
67}