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