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