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