qdrant_client/builders/
lookup_location_builder.rs

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