qdrant_client/builders/
with_lookup_builder.rs

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