Coverage Report

Created: 2026-10-28 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/value-trait-0.12.1/src/option.rs
Line
Count
Source
1
use crate::{
2
    ExtendedValueType, ValueType,
3
    base::{TypedValue, ValueAsScalar, ValueIntoString},
4
    prelude::{ValueAsArray, ValueAsObject, ValueIntoArray, ValueIntoObject},
5
};
6
7
impl<V> ValueIntoString for Option<V>
8
where
9
    V: ValueIntoString,
10
{
11
    type String = V::String;
12
13
0
    fn into_string(self) -> Option<Self::String> {
14
0
        self.and_then(ValueIntoString::into_string)
15
0
    }
16
}
17
18
impl<V> ValueIntoArray for Option<V>
19
where
20
    V: ValueIntoArray,
21
{
22
    type Array = V::Array;
23
0
    fn into_array(self) -> Option<Self::Array> {
24
0
        self.and_then(ValueIntoArray::into_array)
25
0
    }
26
}
27
impl<V> ValueIntoObject for Option<V>
28
where
29
    V: ValueIntoObject,
30
{
31
    type Object = V::Object;
32
0
    fn into_object(self) -> Option<Self::Object> {
33
0
        self.and_then(ValueIntoObject::into_object)
34
0
    }
35
}
36
37
impl<V> TypedValue for Option<V>
38
where
39
    V: TypedValue,
40
{
41
0
    fn value_type(&self) -> ValueType {
42
0
        self.as_ref().map_or(
43
0
            ValueType::Extended(ExtendedValueType::None),
44
            TypedValue::value_type,
45
        )
46
0
    }
47
}
48
49
impl<V> ValueAsScalar for Option<V>
50
where
51
    V: ValueAsScalar,
52
{
53
0
    fn as_null(&self) -> Option<()> {
54
0
        self.as_ref().and_then(ValueAsScalar::as_null)
55
0
    }
56
57
0
    fn as_bool(&self) -> Option<bool> {
58
0
        self.as_ref().and_then(ValueAsScalar::as_bool)
59
0
    }
60
61
0
    fn as_i64(&self) -> Option<i64> {
62
0
        self.as_ref().and_then(ValueAsScalar::as_i64)
63
0
    }
64
65
0
    fn as_u64(&self) -> Option<u64> {
66
0
        self.as_ref().and_then(ValueAsScalar::as_u64)
67
0
    }
68
69
0
    fn as_f64(&self) -> Option<f64> {
70
0
        self.as_ref().and_then(ValueAsScalar::as_f64)
71
0
    }
72
73
0
    fn as_str(&self) -> Option<&str> {
74
0
        self.as_ref().and_then(ValueAsScalar::as_str)
75
0
    }
76
}
77
78
impl<V> ValueAsArray for Option<V>
79
where
80
    V: ValueAsArray,
81
{
82
    type Array = V::Array;
83
84
0
    fn as_array(&self) -> Option<&Self::Array> {
85
0
        self.as_ref().and_then(ValueAsArray::as_array)
86
0
    }
87
}
88
impl<V> ValueAsObject for Option<V>
89
where
90
    V: ValueAsObject,
91
{
92
    type Object = V::Object;
93
94
0
    fn as_object(&self) -> Option<&Self::Object> {
95
0
        self.as_ref().and_then(ValueAsObject::as_object)
96
0
    }
97
}
98
99
impl<V, E> ValueIntoString for Result<V, E>
100
where
101
    V: ValueIntoString,
102
{
103
    type String = V::String;
104
105
0
    fn into_string(self) -> Option<Self::String> {
106
0
        self.ok().and_then(ValueIntoString::into_string)
107
0
    }
108
}
109
110
impl<V, E> ValueIntoArray for Result<V, E>
111
where
112
    V: ValueIntoArray,
113
{
114
    type Array = V::Array;
115
0
    fn into_array(self) -> Option<Self::Array> {
116
0
        self.ok().and_then(ValueIntoArray::into_array)
117
0
    }
118
}
119
impl<V, E> ValueIntoObject for Result<V, E>
120
where
121
    V: ValueIntoObject,
122
{
123
    type Object = V::Object;
124
0
    fn into_object(self) -> Option<Self::Object> {
125
0
        self.ok().and_then(ValueIntoObject::into_object)
126
0
    }
127
}
128
129
impl<V, E> TypedValue for Result<V, E>
130
where
131
    V: TypedValue,
132
{
133
0
    fn value_type(&self) -> ValueType {
134
0
        self.as_ref().ok().map_or(
135
0
            ValueType::Extended(ExtendedValueType::None),
136
            TypedValue::value_type,
137
        )
138
0
    }
139
}
140
141
impl<V, E> ValueAsScalar for Result<V, E>
142
where
143
    V: ValueAsScalar,
144
{
145
0
    fn as_null(&self) -> Option<()> {
146
0
        self.as_ref().ok().and_then(ValueAsScalar::as_null)
147
0
    }
148
0
    fn as_bool(&self) -> Option<bool> {
149
0
        self.as_ref().ok().and_then(ValueAsScalar::as_bool)
150
0
    }
151
152
0
    fn as_i64(&self) -> Option<i64> {
153
0
        self.as_ref().ok().and_then(ValueAsScalar::as_i64)
154
0
    }
155
156
0
    fn as_u64(&self) -> Option<u64> {
157
0
        self.as_ref().ok().and_then(ValueAsScalar::as_u64)
158
0
    }
159
160
0
    fn as_f64(&self) -> Option<f64> {
161
0
        self.as_ref().ok().and_then(ValueAsScalar::as_f64)
162
0
    }
163
164
0
    fn as_str(&self) -> Option<&str> {
165
0
        self.as_ref().ok().and_then(ValueAsScalar::as_str)
166
0
    }
167
}
168
impl<V, E> ValueAsArray for Result<V, E>
169
where
170
    V: ValueAsArray,
171
{
172
    type Array = V::Array;
173
174
0
    fn as_array(&self) -> Option<&Self::Array> {
175
0
        self.as_ref().ok().and_then(ValueAsArray::as_array)
176
0
    }
177
}
178
impl<V, E> ValueAsObject for Result<V, E>
179
where
180
    V: ValueAsObject,
181
{
182
    type Object = V::Object;
183
184
0
    fn as_object(&self) -> Option<&Self::Object> {
185
0
        self.as_ref().ok().and_then(ValueAsObject::as_object)
186
0
    }
187
}
188
189
impl<V> TypedValue for &V
190
where
191
    V: TypedValue,
192
{
193
0
    fn value_type(&self) -> ValueType {
194
0
        (*self).value_type()
195
0
    }
196
}
197
impl<V> ValueAsScalar for &V
198
where
199
    V: ValueAsScalar,
200
{
201
0
    fn as_null(&self) -> Option<()> {
202
0
        (*self).as_null()
203
0
    }
204
205
0
    fn as_bool(&self) -> Option<bool> {
206
0
        (*self).as_bool()
207
0
    }
208
209
0
    fn as_i64(&self) -> Option<i64> {
210
0
        (*self).as_i64()
211
0
    }
212
213
0
    fn as_u64(&self) -> Option<u64> {
214
0
        (*self).as_u64()
215
0
    }
216
217
0
    fn as_f64(&self) -> Option<f64> {
218
0
        (*self).as_f64()
219
0
    }
220
221
0
    fn as_str(&self) -> Option<&str> {
222
0
        (*self).as_str()
223
0
    }
224
}
225
226
impl<V> ValueAsArray for &V
227
where
228
    V: ValueAsArray,
229
{
230
    type Array = V::Array;
231
232
0
    fn as_array(&self) -> Option<&Self::Array> {
233
0
        (*self).as_array()
234
0
    }
235
}
236
impl<V> ValueAsObject for &V
237
where
238
    V: ValueAsObject,
239
{
240
    type Object = V::Object;
241
242
0
    fn as_object(&self) -> Option<&Self::Object> {
243
0
        (*self).as_object()
244
0
    }
245
}