qdrant_client/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#![allow(deprecated)]

use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::marker::PhantomData;

use crate::qdrant::value::Kind::*;
use crate::qdrant::{ListValue, Struct, Value};

/// An error for failed conversions (e.g. calling [`String::try_from(v)`](String::try_from) on an
/// integer [`Value`])
#[deprecated(since = "1.10.0", note = "new functions don't use this type anymore")]
pub struct NotA<T> {
    marker: PhantomData<T>,
}

impl<T> Default for NotA<T> {
    fn default() -> Self {
        NotA {
            marker: PhantomData,
        }
    }
}
impl Error for NotA<Struct> {}

impl Debug for NotA<Struct> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self)
    }
}

impl Display for NotA<Struct> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str("not a Struct")
    }
}

impl Error for NotA<ListValue> {}

impl Debug for NotA<ListValue> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self)
    }
}

impl Display for NotA<ListValue> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str("not a ListValue")
    }
}

// Error + Conversion impl for bool
impl Error for NotA<bool> {}

impl Debug for NotA<bool> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self)
    }
}

impl Display for NotA<bool> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(concat!("not a bool"))
    }
}

impl TryFrom<Value> for bool {
    type Error = NotA<bool>;

    fn try_from(v: Value) -> Result<Self, NotA<bool>> {
        if let Some(BoolValue(t)) = v.kind {
            Ok(t)
        } else {
            Err(NotA::default())
        }
    }
}

// Error + Conversion impl for i64
impl Error for NotA<i64> {}

impl Debug for NotA<i64> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self)
    }
}

impl Display for NotA<i64> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(concat!("not an i64"))
    }
}

impl TryFrom<Value> for i64 {
    type Error = NotA<i64>;

    fn try_from(v: Value) -> Result<Self, NotA<i64>> {
        if let Some(IntegerValue(t)) = v.kind {
            Ok(t)
        } else {
            Err(NotA::default())
        }
    }
}

// Error + Conversion impl for f64
impl Error for NotA<f64> {}

impl Debug for NotA<f64> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self)
    }
}

impl Display for NotA<f64> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(concat!("not a f64"))
    }
}

impl TryFrom<Value> for f64 {
    type Error = NotA<f64>;

    fn try_from(v: Value) -> Result<Self, NotA<f64>> {
        if let Some(DoubleValue(t)) = v.kind {
            Ok(t)
        } else {
            Err(NotA::default())
        }
    }
}

// Error + Conversion impl for string
impl Error for NotA<String> {}

impl Debug for NotA<String> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self)
    }
}

impl Display for NotA<String> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(concat!("not a String"))
    }
}

impl TryFrom<Value> for String {
    type Error = NotA<String>;

    fn try_from(v: Value) -> Result<Self, NotA<String>> {
        if let Some(StringValue(t)) = v.kind {
            Ok(t)
        } else {
            Err(NotA::default())
        }
    }
}