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