Skip to main content

qdrant_client/builders/
lookup_location_builder.rs

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