Skip to main content

qdrant_client/builders/
with_lookup_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[must_use]
5#[derive(Clone)]
6pub struct WithLookupBuilder {
7    /// Name of the collection to use for points lookup
8    pub(crate) collection: Option<String>,
9    /// Options for specifying which payload to include (or not)
10    with_payload: Option<with_payload_selector::SelectorOptions>,
11    /// Options for specifying which vectors to include (or not)
12    with_vectors: Option<with_vectors_selector::SelectorOptions>,
13}
14
15impl WithLookupBuilder {
16    /// Name of the collection to use for points lookup
17    pub fn collection(self, value: String) -> Self {
18        let mut new = self;
19        new.collection = Option::Some(value);
20        new
21    }
22    /// Options for specifying which payload to include (or not)
23    pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
24        self,
25        value: VALUE,
26    ) -> Self {
27        let mut new = self;
28        new.with_payload = Option::Some(value.into());
29        new
30    }
31    /// Options for specifying which vectors to include (or not)
32    pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
33        self,
34        value: VALUE,
35    ) -> Self {
36        let mut new = self;
37        new.with_vectors = Option::Some(value.into());
38        new
39    }
40
41    fn build_inner(self) -> Result<WithLookup, WithLookupBuilderError> {
42        Ok(WithLookup {
43            collection: match self.collection {
44                Some(value) => value,
45                None => {
46                    return Result::Err(core::convert::Into::into(
47                        ::derive_builder::UninitializedFieldError::from("collection"),
48                    ));
49                }
50            },
51            with_payload: { convert_option(&self.with_payload) },
52            with_vectors: { convert_option(&self.with_vectors) },
53        })
54    }
55    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
56    fn create_empty() -> Self {
57        Self {
58            collection: core::default::Default::default(),
59            with_payload: core::default::Default::default(),
60            with_vectors: core::default::Default::default(),
61        }
62    }
63}
64
65impl From<WithLookupBuilder> for WithLookup {
66    fn from(value: WithLookupBuilder) -> Self {
67        value.build_inner().unwrap_or_else(|_| {
68            panic!(
69                "Failed to convert {0} to {1}",
70                "WithLookupBuilder", "WithLookup"
71            )
72        })
73    }
74}
75
76impl WithLookupBuilder {
77    /// Builds the desired type. Can often be omitted.
78    pub fn build(self) -> WithLookup {
79        self.build_inner().unwrap_or_else(|_| {
80            panic!(
81                "Failed to build {0} into {1}",
82                "WithLookupBuilder", "WithLookup"
83            )
84        })
85    }
86}
87
88impl WithLookupBuilder {
89    pub(crate) fn empty() -> Self {
90        Self::create_empty()
91    }
92}
93
94#[non_exhaustive]
95#[derive(Debug)]
96pub enum WithLookupBuilderError {
97    /// Uninitialized field
98    UninitializedField(&'static str),
99    /// Custom validation error
100    ValidationError(String),
101}
102
103// Implementing the Display trait for better error messages
104impl std::fmt::Display for WithLookupBuilderError {
105    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
106        match self {
107            Self::UninitializedField(field) => {
108                write!(f, "`{field}` must be initialized")
109            }
110            Self::ValidationError(error) => write!(f, "{error}"),
111        }
112    }
113}
114
115// Implementing the Error trait
116impl std::error::Error for WithLookupBuilderError {}
117
118// Implementing From trait for conversion from UninitializedFieldError
119impl From<derive_builder::UninitializedFieldError> for WithLookupBuilderError {
120    fn from(error: derive_builder::UninitializedFieldError) -> Self {
121        Self::UninitializedField(error.field_name())
122    }
123}
124
125// Implementing From trait for conversion from String
126impl From<String> for WithLookupBuilderError {
127    fn from(error: String) -> Self {
128        Self::ValidationError(error)
129    }
130}