qdrant_client/builders/
query_batch_points_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct QueryBatchPointsBuilder {
6 pub(crate) collection_name: Option<String>,
7 pub(crate) query_points: Option<Vec<QueryPoints>>,
8 read_consistency: Option<read_consistency::Value>,
10 pub(crate) timeout: Option<Option<u64>>,
12}
13
14impl QueryBatchPointsBuilder {
15 pub fn collection_name(self, value: String) -> Self {
16 let mut new = self;
17 new.collection_name = Option::Some(value);
18 new
19 }
20 pub fn query_points(self, value: Vec<QueryPoints>) -> Self {
21 let mut new = self;
22 new.query_points = Option::Some(value);
23 new
24 }
25 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
27 self,
28 value: VALUE,
29 ) -> Self {
30 let mut new = self;
31 new.read_consistency = Option::Some(value.into());
32 new
33 }
34 pub fn timeout(self, value: u64) -> Self {
36 let mut new = self;
37 new.timeout = Option::Some(Option::Some(value));
38 new
39 }
40
41 fn build_inner(self) -> Result<QueryBatchPoints, QueryBatchPointsBuilderError> {
42 Ok(QueryBatchPoints {
43 collection_name: match self.collection_name {
44 Some(value) => value,
45 None => {
46 return Result::Err(core::convert::Into::into(
47 ::derive_builder::UninitializedFieldError::from("collection_name"),
48 ));
49 }
50 },
51 query_points: match self.query_points {
52 Some(value) => value,
53 None => {
54 return Result::Err(core::convert::Into::into(
55 ::derive_builder::UninitializedFieldError::from("query_points"),
56 ));
57 }
58 },
59 read_consistency: { convert_option(&self.read_consistency) },
60 timeout: self.timeout.unwrap_or_default(),
61 })
62 }
63 fn create_empty() -> Self {
65 Self {
66 collection_name: core::default::Default::default(),
67 query_points: core::default::Default::default(),
68 read_consistency: core::default::Default::default(),
69 timeout: core::default::Default::default(),
70 }
71 }
72}
73
74impl From<QueryBatchPointsBuilder> for QueryBatchPoints {
75 fn from(value: QueryBatchPointsBuilder) -> Self {
76 value.build_inner().unwrap_or_else(|_| {
77 panic!(
78 "Failed to convert {0} to {1}",
79 "QueryBatchPointsBuilder", "QueryBatchPoints"
80 )
81 })
82 }
83}
84
85impl QueryBatchPointsBuilder {
86 pub fn build(self) -> QueryBatchPoints {
88 self.build_inner().unwrap_or_else(|_| {
89 panic!(
90 "Failed to build {0} into {1}",
91 "QueryBatchPointsBuilder", "QueryBatchPoints"
92 )
93 })
94 }
95}
96
97impl QueryBatchPointsBuilder {
98 pub(crate) fn empty() -> Self {
99 Self::create_empty()
100 }
101}
102
103#[non_exhaustive]
105#[derive(Debug)]
106pub enum QueryBatchPointsBuilderError {
107 UninitializedField(&'static str),
109 ValidationError(String),
111}
112
113impl std::fmt::Display for QueryBatchPointsBuilderError {
115 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
116 match self {
117 Self::UninitializedField(field) => {
118 write!(f, "`{field}` must be initialized")
119 }
120 Self::ValidationError(error) => write!(f, "{error}"),
121 }
122 }
123}
124
125impl std::error::Error for QueryBatchPointsBuilderError {}
127
128impl From<derive_builder::UninitializedFieldError> for QueryBatchPointsBuilderError {
130 fn from(error: derive_builder::UninitializedFieldError) -> Self {
131 Self::UninitializedField(error.field_name())
132 }
133}
134
135impl From<String> for QueryBatchPointsBuilderError {
137 fn from(error: String) -> Self {
138 Self::ValidationError(error)
139 }
140}