qdrant_client/builders/
context_input_pair_builder.rs

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