Coverage Report

Created: 2026-01-08 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bson-rust/src/de/serde.rs
Line
Count
Source
1
use std::{
2
    borrow::Cow,
3
    convert::{TryFrom, TryInto},
4
    fmt,
5
    vec,
6
};
7
8
use serde::de::{
9
    self,
10
    Deserialize,
11
    DeserializeSeed,
12
    Deserializer as _,
13
    EnumAccess,
14
    Error as _,
15
    MapAccess,
16
    SeqAccess,
17
    Unexpected,
18
    VariantAccess,
19
    Visitor,
20
};
21
use serde_bytes::ByteBuf;
22
23
use crate::{
24
    bson::{Bson, DbPointer, JavaScriptCodeWithScope, Regex, Timestamp},
25
    datetime::DateTime,
26
    document::{Document, IntoIter},
27
    error::{Error, Result},
28
    oid::ObjectId,
29
    raw::{RawBsonRef, RAW_ARRAY_NEWTYPE, RAW_BSON_NEWTYPE, RAW_DOCUMENT_NEWTYPE},
30
    serde_helpers::HUMAN_READABLE_NEWTYPE,
31
    spec::BinarySubtype,
32
    uuid::UUID_NEWTYPE_NAME,
33
    Binary,
34
    Decimal128,
35
};
36
37
use super::{raw::Decimal128Access, DeserializerHint};
38
39
pub(crate) struct BsonVisitor;
40
41
struct ObjectIdVisitor;
42
43
impl<'de> Visitor<'de> for ObjectIdVisitor {
44
    type Value = ObjectId;
45
46
0
    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
47
0
        formatter.write_str("expecting an ObjectId")
48
0
    }
49
50
    #[inline]
51
0
    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
52
0
    where
53
0
        E: serde::de::Error,
54
    {
55
0
        ObjectId::parse_str(value).map_err(|_| {
56
0
            E::invalid_value(
57
0
                Unexpected::Str(value),
58
0
                &"24-character, big-endian hex string",
59
            )
60
0
        })
61
0
    }
62
63
    #[inline]
64
0
    fn visit_bytes<E>(self, v: &[u8]) -> std::result::Result<Self::Value, E>
65
0
    where
66
0
        E: serde::de::Error,
67
    {
68
0
        let bytes: [u8; 12] = v
69
0
            .try_into()
70
0
            .map_err(|_| E::invalid_length(v.len(), &"12 bytes"))?;
71
0
        Ok(ObjectId::from_bytes(bytes))
72
0
    }
73
74
    #[inline]
75
0
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Self::Value, V::Error>
76
0
    where
77
0
        V: MapAccess<'de>,
78
    {
79
0
        match BsonVisitor.visit_map(&mut visitor)? {
80
0
            Bson::ObjectId(oid) => Ok(oid),
81
0
            bson => {
82
0
                let err = format!(
83
0
                    "expected map containing extended-JSON formatted ObjectId, instead found {}",
84
                    bson
85
                );
86
0
                Err(serde::de::Error::custom(err))
87
            }
88
        }
89
0
    }
90
}
91
92
impl<'de> Deserialize<'de> for ObjectId {
93
0
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
94
0
    where
95
0
        D: serde::Deserializer<'de>,
96
    {
97
0
        if !deserializer.is_human_readable() {
98
0
            deserializer.deserialize_bytes(ObjectIdVisitor)
99
        } else {
100
0
            deserializer.deserialize_any(ObjectIdVisitor)
101
        }
102
0
    }
103
}
104
105
impl<'de> Deserialize<'de> for Document {
106
    /// Deserialize this value given this [`Deserializer`].
107
37.5k
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
108
37.5k
    where
109
37.5k
        D: de::Deserializer<'de>,
110
    {
111
37.5k
        deserializer.deserialize_map(BsonVisitor).and_then(|bson| {
112
24.9k
            if let Bson::Document(doc) = bson {
113
22.9k
                Ok(doc)
114
            } else {
115
1.99k
                let err = format!("expected document, found extended JSON data type: {}", bson);
116
1.99k
                Err(serde::de::Error::invalid_type(Unexpected::Map, &&err[..]))
117
            }
118
24.9k
        })
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::serde::Deserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::Decimal128Deserializer>::{closure#0}
<bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDeserializer>::{closure#0}
Line
Count
Source
111
4.11k
        deserializer.deserialize_map(BsonVisitor).and_then(|bson| {
112
4.11k
            if let Bson::Document(doc) = bson {
113
3.13k
                Ok(doc)
114
            } else {
115
986
                let err = format!("expected document, found extended JSON data type: {}", bson);
116
986
                Err(serde::de::Error::invalid_type(Unexpected::Map, &&err[..]))
117
            }
118
4.11k
        })
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawBsonDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::ObjectIdDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDocumentDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::RegexAccess>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DbPointerAccess>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::BinaryDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DateTimeDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::TimestampDeserializer>::{closure#0}
<bson::document::Document as serde_core::de::Deserialize>::deserialize::<&bson::de::raw::CodeWithScopeAccess>::{closure#0}
Line
Count
Source
111
10.5k
        deserializer.deserialize_map(BsonVisitor).and_then(|bson| {
112
10.5k
            if let Bson::Document(doc) = bson {
113
10.5k
                Ok(doc)
114
            } else {
115
1
                let err = format!("expected document, found extended JSON data type: {}", bson);
116
1
                Err(serde::de::Error::invalid_type(Unexpected::Map, &&err[..]))
117
            }
118
10.5k
        })
<bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDeserializer>::{closure#0}
Line
Count
Source
111
4.04k
        deserializer.deserialize_map(BsonVisitor).and_then(|bson| {
112
4.04k
            if let Bson::Document(doc) = bson {
113
3.04k
                Ok(doc)
114
            } else {
115
1.00k
                let err = format!("expected document, found extended JSON data type: {}", bson);
116
1.00k
                Err(serde::de::Error::invalid_type(Unexpected::Map, &&err[..]))
117
            }
118
4.04k
        })
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawBsonDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::ObjectIdDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDocumentDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::RegexAccess>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DbPointerAccess>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::BinaryDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DateTimeDeserializer>::{closure#0}
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::TimestampDeserializer>::{closure#0}
<bson::document::Document as serde_core::de::Deserialize>::deserialize::<&bson::de::raw::CodeWithScopeAccess>::{closure#0}
Line
Count
Source
111
6.29k
        deserializer.deserialize_map(BsonVisitor).and_then(|bson| {
112
6.29k
            if let Bson::Document(doc) = bson {
113
6.29k
                Ok(doc)
114
            } else {
115
1
                let err = format!("expected document, found extended JSON data type: {}", bson);
116
1
                Err(serde::de::Error::invalid_type(Unexpected::Map, &&err[..]))
117
            }
118
6.29k
        })
119
37.5k
    }
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::serde::Deserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::Decimal128Deserializer>
<bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDeserializer>
Line
Count
Source
107
10.4k
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
108
10.4k
    where
109
10.4k
        D: de::Deserializer<'de>,
110
    {
111
10.4k
        deserializer.deserialize_map(BsonVisitor).and_then(|bson| {
112
            if let Bson::Document(doc) = bson {
113
                Ok(doc)
114
            } else {
115
                let err = format!("expected document, found extended JSON data type: {}", bson);
116
                Err(serde::de::Error::invalid_type(Unexpected::Map, &&err[..]))
117
            }
118
        })
119
10.4k
    }
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawBsonDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::ObjectIdDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDocumentDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::RegexAccess>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DbPointerAccess>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::BinaryDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DateTimeDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::TimestampDeserializer>
<bson::document::Document as serde_core::de::Deserialize>::deserialize::<&bson::de::raw::CodeWithScopeAccess>
Line
Count
Source
107
10.5k
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
108
10.5k
    where
109
10.5k
        D: de::Deserializer<'de>,
110
    {
111
10.5k
        deserializer.deserialize_map(BsonVisitor).and_then(|bson| {
112
            if let Bson::Document(doc) = bson {
113
                Ok(doc)
114
            } else {
115
                let err = format!("expected document, found extended JSON data type: {}", bson);
116
                Err(serde::de::Error::invalid_type(Unexpected::Map, &&err[..]))
117
            }
118
        })
119
10.5k
    }
<bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDeserializer>
Line
Count
Source
107
10.2k
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
108
10.2k
    where
109
10.2k
        D: de::Deserializer<'de>,
110
    {
111
10.2k
        deserializer.deserialize_map(BsonVisitor).and_then(|bson| {
112
            if let Bson::Document(doc) = bson {
113
                Ok(doc)
114
            } else {
115
                let err = format!("expected document, found extended JSON data type: {}", bson);
116
                Err(serde::de::Error::invalid_type(Unexpected::Map, &&err[..]))
117
            }
118
        })
119
10.2k
    }
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawBsonDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::ObjectIdDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDocumentDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::RegexAccess>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DbPointerAccess>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::BinaryDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DateTimeDeserializer>
Unexecuted instantiation: <bson::document::Document as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::TimestampDeserializer>
<bson::document::Document as serde_core::de::Deserialize>::deserialize::<&bson::de::raw::CodeWithScopeAccess>
Line
Count
Source
107
6.30k
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
108
6.30k
    where
109
6.30k
        D: de::Deserializer<'de>,
110
    {
111
6.30k
        deserializer.deserialize_map(BsonVisitor).and_then(|bson| {
112
            if let Bson::Document(doc) = bson {
113
                Ok(doc)
114
            } else {
115
                let err = format!("expected document, found extended JSON data type: {}", bson);
116
                Err(serde::de::Error::invalid_type(Unexpected::Map, &&err[..]))
117
            }
118
        })
119
6.30k
    }
120
}
121
122
impl<'de> Deserialize<'de> for Bson {
123
    #[inline]
124
2.16M
    fn deserialize<D>(deserializer: D) -> std::result::Result<Bson, D::Error>
125
2.16M
    where
126
2.16M
        D: de::Deserializer<'de>,
127
    {
128
2.16M
        deserializer.deserialize_any(BsonVisitor)
129
2.16M
    }
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::serde::Deserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::raw::Decimal128Deserializer>
<bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDeserializer>
Line
Count
Source
124
1.16M
    fn deserialize<D>(deserializer: D) -> std::result::Result<Bson, D::Error>
125
1.16M
    where
126
1.16M
        D: de::Deserializer<'de>,
127
    {
128
1.16M
        deserializer.deserialize_any(BsonVisitor)
129
1.16M
    }
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawBsonDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::raw::ObjectIdDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDocumentDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::RegexAccess>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DbPointerAccess>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::BinaryDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DateTimeDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::TimestampDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&bson::de::raw::CodeWithScopeAccess>
<bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDeserializer>
Line
Count
Source
124
1.00M
    fn deserialize<D>(deserializer: D) -> std::result::Result<Bson, D::Error>
125
1.00M
    where
126
1.00M
        D: de::Deserializer<'de>,
127
    {
128
1.00M
        deserializer.deserialize_any(BsonVisitor)
129
1.00M
    }
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawBsonDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::raw::ObjectIdDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDocumentDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::RegexAccess>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DbPointerAccess>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::BinaryDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DateTimeDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::TimestampDeserializer>
Unexecuted instantiation: <bson::bson::Bson as serde_core::de::Deserialize>::deserialize::<&bson::de::raw::CodeWithScopeAccess>
130
}
131
132
impl<'de> Visitor<'de> for BsonVisitor {
133
    type Value = Bson;
134
135
0
    fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
136
0
        f.write_str("a Bson")
137
0
    }
138
139
    #[inline]
140
22.9k
    fn visit_bool<E>(self, value: bool) -> std::result::Result<Bson, E>
141
22.9k
    where
142
22.9k
        E: serde::de::Error,
143
    {
144
22.9k
        Ok(Bson::Boolean(value))
145
22.9k
    }
146
147
    #[inline]
148
0
    fn visit_i8<E>(self, value: i8) -> std::result::Result<Bson, E>
149
0
    where
150
0
        E: serde::de::Error,
151
    {
152
0
        Ok(Bson::Int32(value as i32))
153
0
    }
154
155
    #[inline]
156
0
    fn visit_u8<E>(self, value: u8) -> std::result::Result<Bson, E>
157
0
    where
158
0
        E: serde::de::Error,
159
    {
160
0
        convert_unsigned_to_signed(value as u64)
161
0
    }
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_u8::<_>
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_u8::<bson::error::Error>
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_u8::<bson::error::Error>
162
163
    #[inline]
164
0
    fn visit_i16<E>(self, value: i16) -> std::result::Result<Bson, E>
165
0
    where
166
0
        E: serde::de::Error,
167
    {
168
0
        Ok(Bson::Int32(value as i32))
169
0
    }
170
171
    #[inline]
172
0
    fn visit_u16<E>(self, value: u16) -> std::result::Result<Bson, E>
173
0
    where
174
0
        E: serde::de::Error,
175
    {
176
0
        convert_unsigned_to_signed(value as u64)
177
0
    }
178
179
    #[inline]
180
18.7k
    fn visit_i32<E>(self, value: i32) -> std::result::Result<Bson, E>
181
18.7k
    where
182
18.7k
        E: serde::de::Error,
183
    {
184
18.7k
        Ok(Bson::Int32(value))
185
18.7k
    }
186
187
    #[inline]
188
0
    fn visit_u32<E>(self, value: u32) -> std::result::Result<Bson, E>
189
0
    where
190
0
        E: serde::de::Error,
191
    {
192
0
        convert_unsigned_to_signed(value as u64)
193
0
    }
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_u32::<_>
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_u32::<bson::error::Error>
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_u32::<bson::error::Error>
194
195
    #[inline]
196
13.2k
    fn visit_i64<E>(self, value: i64) -> std::result::Result<Bson, E>
197
13.2k
    where
198
13.2k
        E: serde::de::Error,
199
    {
200
13.2k
        Ok(Bson::Int64(value))
201
13.2k
    }
202
203
    #[inline]
204
0
    fn visit_u64<E>(self, value: u64) -> std::result::Result<Bson, E>
205
0
    where
206
0
        E: serde::de::Error,
207
    {
208
0
        convert_unsigned_to_signed(value)
209
0
    }
210
211
    #[inline]
212
285k
    fn visit_f64<E>(self, value: f64) -> std::result::Result<Bson, E> {
213
285k
        Ok(Bson::Double(value))
214
285k
    }
215
216
    #[inline]
217
4.76k
    fn visit_str<E>(self, value: &str) -> std::result::Result<Bson, E>
218
4.76k
    where
219
4.76k
        E: serde::de::Error,
220
    {
221
4.76k
        self.visit_string(String::from(value))
222
4.76k
    }
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_str::<_>
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_str::<bson::error::Error>
Line
Count
Source
217
4.76k
    fn visit_str<E>(self, value: &str) -> std::result::Result<Bson, E>
218
4.76k
    where
219
4.76k
        E: serde::de::Error,
220
    {
221
4.76k
        self.visit_string(String::from(value))
222
4.76k
    }
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_str::<bson::error::Error>
223
224
    #[inline]
225
15.6k
    fn visit_string<E>(self, value: String) -> std::result::Result<Bson, E> {
226
15.6k
        Ok(Bson::String(value))
227
15.6k
    }
228
229
    #[inline]
230
0
    fn visit_none<E>(self) -> std::result::Result<Bson, E> {
231
0
        Ok(Bson::Null)
232
0
    }
233
234
    #[inline]
235
0
    fn visit_some<D>(self, deserializer: D) -> std::result::Result<Bson, D::Error>
236
0
    where
237
0
        D: de::Deserializer<'de>,
238
    {
239
0
        deserializer.deserialize_any(self)
240
0
    }
241
242
    #[inline]
243
222k
    fn visit_unit<E>(self) -> std::result::Result<Bson, E> {
244
222k
        Ok(Bson::Null)
245
222k
    }
246
247
    #[inline]
248
11.7k
    fn visit_seq<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
249
11.7k
    where
250
11.7k
        V: SeqAccess<'de>,
251
    {
252
11.7k
        let mut values = Vec::new();
253
254
190k
        while let Some(elem) = visitor.next_element()? {
255
179k
            values.push(elem);
256
179k
        }
257
258
11.5k
        Ok(Bson::Array(values))
259
11.7k
    }
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_seq::<bson::de::serde::SeqDeserializer>
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_seq::<bson::de::raw::DocumentAccess>
Line
Count
Source
248
5.30k
    fn visit_seq<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
249
5.30k
    where
250
5.30k
        V: SeqAccess<'de>,
251
    {
252
5.30k
        let mut values = Vec::new();
253
254
129k
        while let Some(elem) = visitor.next_element()? {
255
124k
            values.push(elem);
256
124k
        }
257
258
5.21k
        Ok(Bson::Array(values))
259
5.30k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_seq::<bson::de::raw::DocumentAccess>
Line
Count
Source
248
6.42k
    fn visit_seq<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
249
6.42k
    where
250
6.42k
        V: SeqAccess<'de>,
251
    {
252
6.42k
        let mut values = Vec::new();
253
254
61.2k
        while let Some(elem) = visitor.next_element()? {
255
54.7k
            values.push(elem);
256
54.7k
        }
257
258
6.32k
        Ok(Bson::Array(values))
259
6.42k
    }
260
261
1.59M
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
1.59M
    where
263
1.59M
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
1.59M
        let mut doc = Document::new();
268
269
3.58M
        while let Some(k) = visitor.next_key::<String>()? {
270
3.51M
            match k.as_str() {
271
3.51M
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
40.4k
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
40.4k
                        where
280
40.4k
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
91
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
91
                                    write!(formatter, "hexstring or byte array")
289
91
                                }
290
291
39.7k
                                fn visit_str<E>(
292
39.7k
                                    self,
293
39.7k
                                    v: &str,
294
39.7k
                                ) -> std::result::Result<Self::Value, E>
295
39.7k
                                where
296
39.7k
                                    E: serde::de::Error,
297
                                {
298
39.7k
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
39.7k
                                }
300
301
53
                                fn visit_borrowed_str<E>(
302
53
                                    self,
303
53
                                    v: &'de str,
304
53
                                ) -> std::result::Result<Self::Value, E>
305
53
                                where
306
53
                                    E: serde::de::Error,
307
                                {
308
53
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
53
                                }
Unexecuted instantiation: <<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::BytesOrHexVisitor as serde_core::de::Visitor>::visit_borrowed_str::<_>
<<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::BytesOrHexVisitor as serde_core::de::Visitor>::visit_borrowed_str::<bson::error::Error>
Line
Count
Source
301
53
                                fn visit_borrowed_str<E>(
302
53
                                    self,
303
53
                                    v: &'de str,
304
53
                                ) -> std::result::Result<Self::Value, E>
305
53
                                where
306
53
                                    E: serde::de::Error,
307
                                {
308
53
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
53
                                }
Unexecuted instantiation: <<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::BytesOrHexVisitor as serde_core::de::Visitor>::visit_borrowed_str::<bson::error::Error>
310
311
547
                                fn visit_bytes<E>(
312
547
                                    self,
313
547
                                    v: &[u8],
314
547
                                ) -> std::result::Result<Self::Value, E>
315
547
                                where
316
547
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
547
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
547
                                }
322
                            }
323
324
40.4k
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
40.4k
                        }
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::serde::Deserializer>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::raw::Decimal128Deserializer>
<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDeserializer>
Line
Count
Source
278
501
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
501
                        where
280
501
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
501
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
501
                        }
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawBsonDeserializer>
<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::raw::ObjectIdDeserializer>
Line
Count
Source
278
18.8k
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
18.8k
                        where
280
18.8k
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
18.8k
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
18.8k
                        }
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDocumentDeserializer>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::RegexAccess>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DbPointerAccess>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::BinaryDeserializer>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DateTimeDeserializer>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::TimestampDeserializer>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&bson::de::raw::CodeWithScopeAccess>
<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDeserializer>
Line
Count
Source
278
269
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
269
                        where
280
269
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
269
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
269
                        }
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawBsonDeserializer>
<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::raw::ObjectIdDeserializer>
Line
Count
Source
278
20.7k
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
20.7k
                        where
280
20.7k
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
20.7k
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
20.7k
                        }
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<bson::de::raw::RawDocumentDeserializer>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::RegexAccess>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DbPointerAccess>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::BinaryDeserializer>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::DateTimeDeserializer>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&mut bson::de::raw::TimestampDeserializer>
Unexecuted instantiation: <<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::<&bson::de::raw::CodeWithScopeAccess>
326
                    }
327
328
40.4k
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
40.3k
                    match bytes_or_hex {
330
539
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
39.7k
                        BytesOrHex::Hex(hex) => {
332
39.7k
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
123
                                |_| {
334
123
                                    V::Error::invalid_value(
335
123
                                        Unexpected::Str(&hex),
336
123
                                        &"24-character, big-endian hex string",
337
                                    )
338
123
                                },
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::serde::MapDeserializer>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::Decimal128Access>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#0}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#0}
Line
Count
Source
333
53
                                |_| {
334
53
                                    V::Error::invalid_value(
335
53
                                        Unexpected::Str(&hex),
336
53
                                        &"24-character, big-endian hex string",
337
                                    )
338
53
                                },
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#0}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#0}
Line
Count
Source
333
70
                                |_| {
334
70
                                    V::Error::invalid_value(
335
70
                                        Unexpected::Str(&hex),
336
70
                                        &"24-character, big-endian hex string",
337
                                    )
338
70
                                },
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#0}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#0}
339
123
                            )?));
340
                        }
341
                    }
342
                }
343
3.47M
                "$symbol" => {
344
10.5k
                    let string: String = visitor.next_value()?;
345
10.5k
                    return Ok(Bson::Symbol(string));
346
                }
347
348
3.46M
                "$numberInt" => {
349
887
                    let string: String = visitor.next_value()?;
350
878
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
119
                        V::Error::invalid_value(
352
119
                            Unexpected::Str(&string),
353
119
                            &"32-bit signed integer as a string",
354
                        )
355
119
                    })?));
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::serde::MapDeserializer>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::Decimal128Access>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#1}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#1}
Line
Count
Source
350
57
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
57
                        V::Error::invalid_value(
352
57
                            Unexpected::Str(&string),
353
57
                            &"32-bit signed integer as a string",
354
                        )
355
57
                    })?));
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#1}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#1}
Line
Count
Source
350
62
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
62
                        V::Error::invalid_value(
352
62
                            Unexpected::Str(&string),
353
62
                            &"32-bit signed integer as a string",
354
                        )
355
62
                    })?));
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#1}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#1}
356
                }
357
358
3.46M
                "$numberLong" => {
359
2.91k
                    let string: String = visitor.next_value()?;
360
2.90k
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
156
                        V::Error::invalid_value(
362
156
                            Unexpected::Str(&string),
363
156
                            &"64-bit signed integer as a string",
364
                        )
365
156
                    })?));
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::serde::MapDeserializer>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::Decimal128Access>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#2}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#2}
Line
Count
Source
360
72
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
72
                        V::Error::invalid_value(
362
72
                            Unexpected::Str(&string),
363
72
                            &"64-bit signed integer as a string",
364
                        )
365
72
                    })?));
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#2}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#2}
Line
Count
Source
360
84
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
84
                        V::Error::invalid_value(
362
84
                            Unexpected::Str(&string),
363
84
                            &"64-bit signed integer as a string",
364
                        )
365
84
                    })?));
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#2}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#2}
366
                }
367
368
3.45M
                "$numberDouble" => {
369
4.92k
                    let string: String = visitor.next_value()?;
370
4.91k
                    let val = match string.as_str() {
371
4.91k
                        "Infinity" => Bson::Double(f64::INFINITY),
372
4.86k
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
4.38k
                        "NaN" => Bson::Double(f64::NAN),
374
3.21k
                        _ => Bson::Double(string.parse().map_err(|_| {
375
107
                            V::Error::invalid_value(
376
107
                                Unexpected::Str(&string),
377
107
                                &"64-bit signed integer as a string",
378
                            )
379
107
                        })?),
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::serde::MapDeserializer>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::Decimal128Access>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#3}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#3}
Line
Count
Source
374
65
                        _ => Bson::Double(string.parse().map_err(|_| {
375
65
                            V::Error::invalid_value(
376
65
                                Unexpected::Str(&string),
377
65
                                &"64-bit signed integer as a string",
378
                            )
379
65
                        })?),
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#3}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#3}
Line
Count
Source
374
42
                        _ => Bson::Double(string.parse().map_err(|_| {
375
42
                            V::Error::invalid_value(
376
42
                                Unexpected::Str(&string),
377
42
                                &"64-bit signed integer as a string",
378
                            )
379
42
                        })?),
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#3}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#3}
380
                    };
381
4.81k
                    return Ok(val);
382
                }
383
384
3.45M
                "$binary" => {
385
133k
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
133k
                        extjson::models::Binary { body: v }
388
133k
                            .parse()
389
133k
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
3.31M
                "$uuid" => {
394
1.33k
                    let v: String = visitor.next_value()?;
395
1.29k
                    let uuid = extjson::models::Uuid { value: v }
396
1.29k
                        .parse()
397
1.29k
                        .map_err(serde::de::Error::custom)?;
398
698
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
3.31M
                "$code" => {
402
52.4k
                    let code = visitor.next_value::<String>()?;
403
52.3k
                    if let Some(key) = visitor.next_key::<String>()? {
404
17.3k
                        if key.as_str() == "$scope" {
405
17.2k
                            let scope = visitor.next_value::<Document>()?;
406
17.2k
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
17.2k
                                code,
408
17.2k
                                scope,
409
17.2k
                            }));
410
                        } else {
411
34
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
35.0k
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
3.26M
                "$scope" => {
419
1.35k
                    let scope = visitor.next_value::<Document>()?;
420
510
                    if let Some(key) = visitor.next_key::<String>()? {
421
506
                        if key.as_str() == "$code" {
422
497
                            let code = visitor.next_value::<String>()?;
423
493
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
493
                                code,
425
493
                                scope,
426
493
                            }));
427
                        } else {
428
9
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
2
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
3.26M
                "$timestamp" => {
436
20.4k
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
19.9k
                    return Ok(Bson::Timestamp(Timestamp {
438
19.9k
                        time: ts.t,
439
19.9k
                        increment: ts.i,
440
19.9k
                    }));
441
                }
442
443
3.24M
                "$regularExpression" => {
444
374k
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
374k
                        Regex::from_strings(re.pattern, re.options)
447
374k
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
2.86M
                "$dbPointer" => {
452
39.6k
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
39.3k
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
39.2k
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
2.82M
                "$date" => {
460
104k
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
103k
                        extjson::models::DateTime { body: dt }
463
103k
                            .parse()
464
103k
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
2.72M
                "$maxKey" => {
469
149k
                    let i = visitor.next_value::<u8>()?;
470
149k
                    return extjson::models::MaxKey { value: i }
471
149k
                        .parse()
472
149k
                        .map_err(serde::de::Error::custom);
473
                }
474
475
2.57M
                "$minKey" => {
476
164k
                    let i = visitor.next_value::<u8>()?;
477
164k
                    return extjson::models::MinKey { value: i }
478
164k
                        .parse()
479
164k
                        .map_err(serde::de::Error::custom);
480
                }
481
482
2.41M
                "$undefined" => {
483
369k
                    let b = visitor.next_value::<bool>()?;
484
369k
                    return extjson::models::Undefined { value: b }
485
369k
                        .parse()
486
369k
                        .map_err(serde::de::Error::custom);
487
                }
488
489
2.04M
                "$numberDecimal" => {
490
42.8k
                    let string: String = visitor.next_value()?;
491
42.8k
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
1.12k
                        |_| {
493
1.12k
                            V::Error::invalid_value(
494
1.12k
                                Unexpected::Str(&string),
495
1.12k
                                &"decimal128 as a string",
496
                            )
497
1.12k
                        },
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::serde::MapDeserializer>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::Decimal128Access>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#4}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#4}
Line
Count
Source
492
573
                        |_| {
493
573
                            V::Error::invalid_value(
494
573
                                Unexpected::Str(&string),
495
573
                                &"decimal128 as a string",
496
                            )
497
573
                        },
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>::{closure#4}
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>::{closure#4}
Line
Count
Source
492
554
                        |_| {
493
554
                            V::Error::invalid_value(
494
554
                                Unexpected::Str(&string),
495
554
                                &"decimal128 as a string",
496
                            )
497
554
                        },
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>::{closure#4}
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>::{closure#4}
498
1.12k
                    )?));
499
                }
500
501
1.99M
                "$numberDecimalBytes" => {
502
12.6k
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
12.5k
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
12.5k
                        &bytes,
505
15
                    )?));
506
                }
507
508
1.98M
                k => {
509
1.98M
                    let v = visitor.next_value::<Bson>()?;
510
1.98M
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
66.8k
        Ok(Bson::Document(doc))
516
1.59M
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::serde::MapDeserializer>
Line
Count
Source
261
29.2k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
29.2k
    where
263
29.2k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
29.2k
        let mut doc = Document::new();
268
269
29.2k
        while let Some(k) = visitor.next_key::<String>()? {
270
29.2k
            match k.as_str() {
271
29.2k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
29.2k
                "$symbol" => {
344
4.52k
                    let string: String = visitor.next_value()?;
345
4.52k
                    return Ok(Bson::Symbol(string));
346
                }
347
348
24.7k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
24.7k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
24.7k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
24.7k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
24.7k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
24.7k
                "$code" => {
402
24.7k
                    let code = visitor.next_value::<String>()?;
403
24.7k
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
24.7k
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
0
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
0
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
0
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
29.2k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::Decimal128Access>
Line
Count
Source
261
12.2k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
12.2k
    where
263
12.2k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
12.2k
        let mut doc = Document::new();
268
269
12.2k
        while let Some(k) = visitor.next_key::<String>()? {
270
12.2k
            match k.as_str() {
271
12.2k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
12.2k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
12.2k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
12.2k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
12.2k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
12.2k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
12.2k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
12.2k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
12.2k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
12.2k
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
12.2k
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
12.2k
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
12.2k
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
12.2k
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
12.2k
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
12.2k
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
12.2k
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
12.2k
                "$numberDecimalBytes" => {
502
12.2k
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
12.2k
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
12.2k
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
12.2k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>
Line
Count
Source
261
141k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
141k
    where
263
141k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
141k
        let mut doc = Document::new();
268
269
141k
        while let Some(k) = visitor.next_key::<String>()? {
270
141k
            match k.as_str() {
271
141k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
141k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
141k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
141k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
141k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
141k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
141k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
141k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
141k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
141k
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
141k
                "$regularExpression" => {
444
141k
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
141k
                        Regex::from_strings(re.pattern, re.options)
447
141k
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
141k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>
Line
Count
Source
261
82.8k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
82.8k
    where
263
82.8k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
82.8k
        let mut doc = Document::new();
268
269
82.8k
        while let Some(k) = visitor.next_key::<String>()? {
270
82.8k
            match k.as_str() {
271
82.8k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
82.8k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
82.8k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
82.8k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
82.8k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
82.8k
                "$binary" => {
385
82.8k
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
82.8k
                        extjson::models::Binary { body: v }
388
82.8k
                            .parse()
389
82.8k
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
0
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
0
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
0
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
0
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
0
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
82.8k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>
Line
Count
Source
261
321k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
321k
    where
263
321k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
321k
        let mut doc = Document::new();
268
269
321k
        while let Some(k) = visitor.next_key::<String>()? {
270
321k
            match k.as_str() {
271
321k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
321k
                "$symbol" => {
344
5.57k
                    let string: String = visitor.next_value()?;
345
5.57k
                    return Ok(Bson::Symbol(string));
346
                }
347
348
315k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
315k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
315k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
315k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
315k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
315k
                "$code" => {
402
5.85k
                    let code = visitor.next_value::<String>()?;
403
5.85k
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
5.85k
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
309k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
309k
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
309k
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
309k
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
309k
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
309k
                "$maxKey" => {
469
139k
                    let i = visitor.next_value::<u8>()?;
470
139k
                    return extjson::models::MaxKey { value: i }
471
139k
                        .parse()
472
139k
                        .map_err(serde::de::Error::custom);
473
                }
474
475
170k
                "$minKey" => {
476
77.0k
                    let i = visitor.next_value::<u8>()?;
477
77.0k
                    return extjson::models::MinKey { value: i }
478
77.0k
                        .parse()
479
77.0k
                        .map_err(serde::de::Error::custom);
480
                }
481
482
93.3k
                "$undefined" => {
483
93.3k
                    let b = visitor.next_value::<bool>()?;
484
93.3k
                    return extjson::models::Undefined { value: b }
485
93.3k
                        .parse()
486
93.3k
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
321k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>
Line
Count
Source
261
49.2k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
49.2k
    where
263
49.2k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
49.2k
        let mut doc = Document::new();
268
269
49.2k
        while let Some(k) = visitor.next_key::<String>()? {
270
49.2k
            match k.as_str() {
271
49.2k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
49.2k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
49.2k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
49.2k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
49.2k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
49.2k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
49.2k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
49.2k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
49.2k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
49.2k
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
49.2k
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
49.2k
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
49.2k
                "$date" => {
460
49.2k
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
49.2k
                        extjson::models::DateTime { body: dt }
463
49.2k
                            .parse()
464
49.2k
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
49.2k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>
Line
Count
Source
261
83.6k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
83.6k
    where
263
83.6k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
83.6k
        let mut doc = Document::new();
268
269
1.12M
        while let Some(k) = visitor.next_key::<String>()? {
270
1.09M
            match k.as_str() {
271
1.09M
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
501
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
460
                    match bytes_or_hex {
330
407
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
53
                        BytesOrHex::Hex(hex) => {
332
53
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
53
                            )?));
340
                        }
341
                    }
342
                }
343
1.09M
                "$symbol" => {
344
242
                    let string: String = visitor.next_value()?;
345
241
                    return Ok(Bson::Symbol(string));
346
                }
347
348
1.09M
                "$numberInt" => {
349
76
                    let string: String = visitor.next_value()?;
350
72
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
57
                    })?));
356
                }
357
358
1.09M
                "$numberLong" => {
359
2.81k
                    let string: String = visitor.next_value()?;
360
2.81k
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
72
                    })?));
366
                }
367
368
1.08M
                "$numberDouble" => {
369
2.27k
                    let string: String = visitor.next_value()?;
370
2.27k
                    let val = match string.as_str() {
371
2.27k
                        "Infinity" => Bson::Double(f64::INFINITY),
372
2.23k
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
1.98k
                        "NaN" => Bson::Double(f64::NAN),
374
1.60k
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
65
                        })?),
380
                    };
381
2.20k
                    return Ok(val);
382
                }
383
384
1.08M
                "$binary" => {
385
736
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
646
                        extjson::models::Binary { body: v }
388
646
                            .parse()
389
646
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
1.08M
                "$uuid" => {
394
336
                    let v: String = visitor.next_value()?;
395
320
                    let uuid = extjson::models::Uuid { value: v }
396
320
                        .parse()
397
320
                        .map_err(serde::de::Error::custom)?;
398
28
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
1.08M
                "$code" => {
402
1.02k
                    let code = visitor.next_value::<String>()?;
403
1.00k
                    if let Some(key) = visitor.next_key::<String>()? {
404
148
                        if key.as_str() == "$scope" {
405
122
                            let scope = visitor.next_value::<Document>()?;
406
117
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
117
                                code,
408
117
                                scope,
409
117
                            }));
410
                        } else {
411
26
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
857
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
1.08M
                "$scope" => {
419
770
                    let scope = visitor.next_value::<Document>()?;
420
346
                    if let Some(key) = visitor.next_key::<String>()? {
421
344
                        if key.as_str() == "$code" {
422
339
                            let code = visitor.next_value::<String>()?;
423
337
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
337
                                code,
425
337
                                scope,
426
337
                            }));
427
                        } else {
428
5
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
1
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
1.08M
                "$timestamp" => {
436
668
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
416
                    return Ok(Bson::Timestamp(Timestamp {
438
416
                        time: ts.t,
439
416
                        increment: ts.i,
440
416
                    }));
441
                }
442
443
1.08M
                "$regularExpression" => {
444
1.45k
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
1.38k
                        Regex::from_strings(re.pattern, re.options)
447
1.38k
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
1.08M
                "$dbPointer" => {
452
1.63k
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
1.50k
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
1.48k
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
1.08M
                "$date" => {
460
12.6k
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
12.1k
                        extjson::models::DateTime { body: dt }
463
12.1k
                            .parse()
464
12.1k
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
1.06M
                "$maxKey" => {
469
638
                    let i = visitor.next_value::<u8>()?;
470
543
                    return extjson::models::MaxKey { value: i }
471
543
                        .parse()
472
543
                        .map_err(serde::de::Error::custom);
473
                }
474
475
1.06M
                "$minKey" => {
476
514
                    let i = visitor.next_value::<u8>()?;
477
398
                    return extjson::models::MinKey { value: i }
478
398
                        .parse()
479
398
                        .map_err(serde::de::Error::custom);
480
                }
481
482
1.06M
                "$undefined" => {
483
870
                    let b = visitor.next_value::<bool>()?;
484
841
                    return extjson::models::Undefined { value: b }
485
841
                        .parse()
486
841
                        .map_err(serde::de::Error::custom);
487
                }
488
489
1.06M
                "$numberDecimal" => {
490
26.0k
                    let string: String = visitor.next_value()?;
491
26.0k
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
573
                    )?));
499
                }
500
501
1.03M
                "$numberDecimalBytes" => {
502
264
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
234
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
234
                        &bytes,
505
9
                    )?));
506
                }
507
508
1.03M
                k => {
509
1.03M
                    let v = visitor.next_value::<Bson>()?;
510
1.03M
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
26.9k
        Ok(Bson::Document(doc))
516
83.6k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>
Line
Count
Source
261
18.8k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
18.8k
    where
263
18.8k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
18.8k
        let mut doc = Document::new();
268
269
18.8k
        while let Some(k) = visitor.next_key::<String>()? {
270
18.8k
            match k.as_str() {
271
18.8k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
18.8k
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
18.8k
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
18.8k
                        BytesOrHex::Hex(hex) => {
332
18.8k
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
0
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
0
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
0
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
0
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
0
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
0
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
0
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
0
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
0
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
0
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
18.8k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>
Line
Count
Source
261
12.6k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
12.6k
    where
263
12.6k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
12.6k
        let mut doc = Document::new();
268
269
12.6k
        while let Some(k) = visitor.next_key::<String>()? {
270
12.6k
            match k.as_str() {
271
12.6k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
12.6k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
12.6k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
12.6k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
12.6k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
12.6k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
12.6k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
12.6k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
12.6k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
12.6k
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
12.6k
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
12.6k
                "$dbPointer" => {
452
12.6k
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
12.6k
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
12.6k
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
12.6k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>
Line
Count
Source
261
13.3k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
13.3k
    where
263
13.3k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
13.3k
        let mut doc = Document::new();
268
269
13.3k
        while let Some(k) = visitor.next_key::<String>()? {
270
13.3k
            match k.as_str() {
271
13.3k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
13.3k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
13.3k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
13.3k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
13.3k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
13.3k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
13.3k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
13.3k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
13.3k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
13.3k
                "$timestamp" => {
436
13.3k
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
13.3k
                    return Ok(Bson::Timestamp(Timestamp {
438
13.3k
                        time: ts.t,
439
13.3k
                        increment: ts.i,
440
13.3k
                    }));
441
                }
442
443
0
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
13.3k
    }
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>
Line
Count
Source
261
10.5k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
10.5k
    where
263
10.5k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
10.5k
        let mut doc = Document::new();
268
269
10.5k
        while let Some(k) = visitor.next_key::<String>()? {
270
10.5k
            match k.as_str() {
271
10.5k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
10.5k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
10.5k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
10.5k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
10.5k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
10.5k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
10.5k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
10.5k
                "$code" => {
402
10.5k
                    let code = visitor.next_value::<String>()?;
403
10.5k
                    if let Some(key) = visitor.next_key::<String>()? {
404
10.5k
                        if key.as_str() == "$scope" {
405
10.5k
                            let scope = visitor.next_value::<Document>()?;
406
10.5k
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
10.5k
                                code,
408
10.5k
                                scope,
409
10.5k
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
0
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
0
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
0
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
10.5k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RegexAccess>
Line
Count
Source
261
231k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
231k
    where
263
231k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
231k
        let mut doc = Document::new();
268
269
231k
        while let Some(k) = visitor.next_key::<String>()? {
270
231k
            match k.as_str() {
271
231k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
231k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
231k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
231k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
231k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
231k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
231k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
231k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
231k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
231k
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
231k
                "$regularExpression" => {
444
231k
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
231k
                        Regex::from_strings(re.pattern, re.options)
447
231k
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
231k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::BinaryAccess>
Line
Count
Source
261
49.7k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
49.7k
    where
263
49.7k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
49.7k
        let mut doc = Document::new();
268
269
49.7k
        while let Some(k) = visitor.next_key::<String>()? {
270
49.7k
            match k.as_str() {
271
49.7k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
49.7k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
49.7k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
49.7k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
49.7k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
49.7k
                "$binary" => {
385
49.7k
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
49.7k
                        extjson::models::Binary { body: v }
388
49.7k
                            .parse()
389
49.7k
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
0
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
0
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
0
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
0
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
0
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
49.7k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawBsonAccess>
Line
Count
Source
261
371k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
371k
    where
263
371k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
371k
        let mut doc = Document::new();
268
269
371k
        while let Some(k) = visitor.next_key::<String>()? {
270
371k
            match k.as_str() {
271
371k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
371k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
371k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
371k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
371k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
371k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
371k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
371k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
371k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
371k
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
371k
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
371k
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
371k
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
371k
                "$maxKey" => {
469
9.09k
                    let i = visitor.next_value::<u8>()?;
470
9.09k
                    return extjson::models::MaxKey { value: i }
471
9.09k
                        .parse()
472
9.09k
                        .map_err(serde::de::Error::custom);
473
                }
474
475
361k
                "$minKey" => {
476
86.4k
                    let i = visitor.next_value::<u8>()?;
477
86.4k
                    return extjson::models::MinKey { value: i }
478
86.4k
                        .parse()
479
86.4k
                        .map_err(serde::de::Error::custom);
480
                }
481
482
275k
                "$undefined" => {
483
275k
                    let b = visitor.next_value::<bool>()?;
484
275k
                    return extjson::models::Undefined { value: b }
485
275k
                        .parse()
486
275k
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
371k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DateTimeAccess>
Line
Count
Source
261
31.7k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
31.7k
    where
263
31.7k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
31.7k
        let mut doc = Document::new();
268
269
31.7k
        while let Some(k) = visitor.next_key::<String>()? {
270
31.7k
            match k.as_str() {
271
31.7k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
31.7k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
31.7k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
31.7k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
31.7k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
31.7k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
31.7k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
31.7k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
31.7k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
31.7k
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
31.7k
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
31.7k
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
31.7k
                "$date" => {
460
31.7k
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
31.7k
                        extjson::models::DateTime { body: dt }
463
31.7k
                            .parse()
464
31.7k
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
31.7k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DocumentAccess>
Line
Count
Source
261
83.7k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
83.7k
    where
263
83.7k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
83.7k
        let mut doc = Document::new();
268
269
1.02M
        while let Some(k) = visitor.next_key::<String>()? {
270
987k
            match k.as_str() {
271
987k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
269
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
203
                    match bytes_or_hex {
330
132
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
71
                        BytesOrHex::Hex(hex) => {
332
71
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
70
                            )?));
340
                        }
341
                    }
342
                }
343
986k
                "$symbol" => {
344
226
                    let string: String = visitor.next_value()?;
345
223
                    return Ok(Bson::Symbol(string));
346
                }
347
348
986k
                "$numberInt" => {
349
811
                    let string: String = visitor.next_value()?;
350
806
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
62
                    })?));
356
                }
357
358
985k
                "$numberLong" => {
359
99
                    let string: String = visitor.next_value()?;
360
96
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
84
                    })?));
366
                }
367
368
985k
                "$numberDouble" => {
369
2.65k
                    let string: String = visitor.next_value()?;
370
2.64k
                    let val = match string.as_str() {
371
2.64k
                        "Infinity" => Bson::Double(f64::INFINITY),
372
2.62k
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
2.40k
                        "NaN" => Bson::Double(f64::NAN),
374
1.61k
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
42
                        })?),
380
                    };
381
2.60k
                    return Ok(val);
382
                }
383
384
983k
                "$binary" => {
385
181
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
82
                        extjson::models::Binary { body: v }
388
82
                            .parse()
389
82
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
982k
                "$uuid" => {
394
996
                    let v: String = visitor.next_value()?;
395
970
                    let uuid = extjson::models::Uuid { value: v }
396
970
                        .parse()
397
970
                        .map_err(serde::de::Error::custom)?;
398
670
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
981k
                "$code" => {
402
3.95k
                    let code = visitor.next_value::<String>()?;
403
3.92k
                    if let Some(key) = visitor.next_key::<String>()? {
404
302
                        if key.as_str() == "$scope" {
405
294
                            let scope = visitor.next_value::<Document>()?;
406
292
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
292
                                code,
408
292
                                scope,
409
292
                            }));
410
                        } else {
411
8
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
3.62k
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
977k
                "$scope" => {
419
585
                    let scope = visitor.next_value::<Document>()?;
420
164
                    if let Some(key) = visitor.next_key::<String>()? {
421
162
                        if key.as_str() == "$code" {
422
158
                            let code = visitor.next_value::<String>()?;
423
156
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
156
                                code,
425
156
                                scope,
426
156
                            }));
427
                        } else {
428
4
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
1
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
977k
                "$timestamp" => {
436
1.93k
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
1.63k
                    return Ok(Bson::Timestamp(Timestamp {
438
1.63k
                        time: ts.t,
439
1.63k
                        increment: ts.i,
440
1.63k
                    }));
441
                }
442
443
975k
                "$regularExpression" => {
444
84
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
8
                        Regex::from_strings(re.pattern, re.options)
447
8
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
975k
                "$dbPointer" => {
452
633
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
448
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
428
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
974k
                "$date" => {
460
10.7k
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
10.2k
                        extjson::models::DateTime { body: dt }
463
10.2k
                            .parse()
464
10.2k
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
964k
                "$maxKey" => {
469
673
                    let i = visitor.next_value::<u8>()?;
470
569
                    return extjson::models::MaxKey { value: i }
471
569
                        .parse()
472
569
                        .map_err(serde::de::Error::custom);
473
                }
474
475
963k
                "$minKey" => {
476
413
                    let i = visitor.next_value::<u8>()?;
477
288
                    return extjson::models::MinKey { value: i }
478
288
                        .parse()
479
288
                        .map_err(serde::de::Error::custom);
480
                }
481
482
962k
                "$undefined" => {
483
124
                    let b = visitor.next_value::<bool>()?;
484
78
                    return extjson::models::Undefined { value: b }
485
78
                        .parse()
486
78
                        .map_err(serde::de::Error::custom);
487
                }
488
489
962k
                "$numberDecimal" => {
490
16.7k
                    let string: String = visitor.next_value()?;
491
16.7k
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
554
                    )?));
499
                }
500
501
946k
                "$numberDecimalBytes" => {
502
118
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
63
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
63
                        &bytes,
505
6
                    )?));
506
                }
507
508
945k
                k => {
509
945k
                    let v = visitor.next_value::<Bson>()?;
510
945k
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
39.8k
        Ok(Bson::Document(doc))
516
83.7k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::ObjectIdAccess>
Line
Count
Source
261
20.7k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
20.7k
    where
263
20.7k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
20.7k
        let mut doc = Document::new();
268
269
20.7k
        while let Some(k) = visitor.next_key::<String>()? {
270
20.7k
            match k.as_str() {
271
20.7k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
20.7k
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
20.7k
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
20.7k
                        BytesOrHex::Hex(hex) => {
332
20.7k
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
0
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
0
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
0
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
0
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
0
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
0
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
0
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
0
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
0
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
0
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
20.7k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::DbPointerAccess>
Line
Count
Source
261
24.7k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
24.7k
    where
263
24.7k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
24.7k
        let mut doc = Document::new();
268
269
24.7k
        while let Some(k) = visitor.next_key::<String>()? {
270
24.7k
            match k.as_str() {
271
24.7k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
24.7k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
24.7k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
24.7k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
24.7k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
24.7k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
24.7k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
24.7k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
24.7k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
24.7k
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
24.7k
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
24.7k
                "$dbPointer" => {
452
24.7k
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
24.7k
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
24.7k
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
24.7k
    }
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::TimestampAccess>
Line
Count
Source
261
4.49k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
4.49k
    where
263
4.49k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
4.49k
        let mut doc = Document::new();
268
269
4.49k
        while let Some(k) = visitor.next_key::<String>()? {
270
4.49k
            match k.as_str() {
271
4.49k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
4.49k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
4.49k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
4.49k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
4.49k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
4.49k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
4.49k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
4.49k
                "$code" => {
402
0
                    let code = visitor.next_value::<String>()?;
403
0
                    if let Some(key) = visitor.next_key::<String>()? {
404
0
                        if key.as_str() == "$scope" {
405
0
                            let scope = visitor.next_value::<Document>()?;
406
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
0
                                code,
408
0
                                scope,
409
0
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
4.49k
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
4.49k
                "$timestamp" => {
436
4.49k
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
4.49k
                    return Ok(Bson::Timestamp(Timestamp {
438
4.49k
                        time: ts.t,
439
4.49k
                        increment: ts.i,
440
4.49k
                    }));
441
                }
442
443
0
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
4.49k
    }
Unexecuted instantiation: <bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::RawDocumentAccess>
<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::<bson::de::raw::CodeWithScopeAccess>
Line
Count
Source
261
6.30k
    fn visit_map<V>(self, mut visitor: V) -> std::result::Result<Bson, V::Error>
262
6.30k
    where
263
6.30k
        V: MapAccess<'de>,
264
    {
265
        use crate::extjson;
266
267
6.30k
        let mut doc = Document::new();
268
269
6.30k
        while let Some(k) = visitor.next_key::<String>()? {
270
6.30k
            match k.as_str() {
271
6.30k
                "$oid" => {
272
                    enum BytesOrHex<'a> {
273
                        Bytes([u8; 12]),
274
                        Hex(Cow<'a, str>),
275
                    }
276
277
                    impl<'a, 'de: 'a> Deserialize<'de> for BytesOrHex<'a> {
278
                        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
279
                        where
280
                            D: serde::Deserializer<'de>,
281
                        {
282
                            struct BytesOrHexVisitor;
283
284
                            impl<'de> Visitor<'de> for BytesOrHexVisitor {
285
                                type Value = BytesOrHex<'de>;
286
287
                                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
288
                                    write!(formatter, "hexstring or byte array")
289
                                }
290
291
                                fn visit_str<E>(
292
                                    self,
293
                                    v: &str,
294
                                ) -> std::result::Result<Self::Value, E>
295
                                where
296
                                    E: serde::de::Error,
297
                                {
298
                                    Ok(BytesOrHex::Hex(Cow::Owned(v.to_string())))
299
                                }
300
301
                                fn visit_borrowed_str<E>(
302
                                    self,
303
                                    v: &'de str,
304
                                ) -> std::result::Result<Self::Value, E>
305
                                where
306
                                    E: serde::de::Error,
307
                                {
308
                                    Ok(BytesOrHex::Hex(Cow::Borrowed(v)))
309
                                }
310
311
                                fn visit_bytes<E>(
312
                                    self,
313
                                    v: &[u8],
314
                                ) -> std::result::Result<Self::Value, E>
315
                                where
316
                                    E: serde::de::Error,
317
                                {
318
                                    Ok(BytesOrHex::Bytes(
319
                                        v.try_into().map_err(serde::de::Error::custom)?,
320
                                    ))
321
                                }
322
                            }
323
324
                            deserializer.deserialize_any(BytesOrHexVisitor)
325
                        }
326
                    }
327
328
0
                    let bytes_or_hex: BytesOrHex = visitor.next_value()?;
329
0
                    match bytes_or_hex {
330
0
                        BytesOrHex::Bytes(b) => return Ok(Bson::ObjectId(ObjectId::from_bytes(b))),
331
0
                        BytesOrHex::Hex(hex) => {
332
0
                            return Ok(Bson::ObjectId(ObjectId::parse_str(&hex).map_err(
333
                                |_| {
334
                                    V::Error::invalid_value(
335
                                        Unexpected::Str(&hex),
336
                                        &"24-character, big-endian hex string",
337
                                    )
338
                                },
339
0
                            )?));
340
                        }
341
                    }
342
                }
343
6.30k
                "$symbol" => {
344
0
                    let string: String = visitor.next_value()?;
345
0
                    return Ok(Bson::Symbol(string));
346
                }
347
348
6.30k
                "$numberInt" => {
349
0
                    let string: String = visitor.next_value()?;
350
0
                    return Ok(Bson::Int32(string.parse().map_err(|_| {
351
                        V::Error::invalid_value(
352
                            Unexpected::Str(&string),
353
                            &"32-bit signed integer as a string",
354
                        )
355
0
                    })?));
356
                }
357
358
6.30k
                "$numberLong" => {
359
0
                    let string: String = visitor.next_value()?;
360
0
                    return Ok(Bson::Int64(string.parse().map_err(|_| {
361
                        V::Error::invalid_value(
362
                            Unexpected::Str(&string),
363
                            &"64-bit signed integer as a string",
364
                        )
365
0
                    })?));
366
                }
367
368
6.30k
                "$numberDouble" => {
369
0
                    let string: String = visitor.next_value()?;
370
0
                    let val = match string.as_str() {
371
0
                        "Infinity" => Bson::Double(f64::INFINITY),
372
0
                        "-Infinity" => Bson::Double(f64::NEG_INFINITY),
373
0
                        "NaN" => Bson::Double(f64::NAN),
374
0
                        _ => Bson::Double(string.parse().map_err(|_| {
375
                            V::Error::invalid_value(
376
                                Unexpected::Str(&string),
377
                                &"64-bit signed integer as a string",
378
                            )
379
0
                        })?),
380
                    };
381
0
                    return Ok(val);
382
                }
383
384
6.30k
                "$binary" => {
385
0
                    let v = visitor.next_value::<extjson::models::BinaryBody>()?;
386
                    return Ok(Bson::Binary(
387
0
                        extjson::models::Binary { body: v }
388
0
                            .parse()
389
0
                            .map_err(serde::de::Error::custom)?,
390
                    ));
391
                }
392
393
6.30k
                "$uuid" => {
394
0
                    let v: String = visitor.next_value()?;
395
0
                    let uuid = extjson::models::Uuid { value: v }
396
0
                        .parse()
397
0
                        .map_err(serde::de::Error::custom)?;
398
0
                    return Ok(Bson::Binary(uuid));
399
                }
400
401
6.30k
                "$code" => {
402
6.30k
                    let code = visitor.next_value::<String>()?;
403
6.30k
                    if let Some(key) = visitor.next_key::<String>()? {
404
6.30k
                        if key.as_str() == "$scope" {
405
6.30k
                            let scope = visitor.next_value::<Document>()?;
406
6.29k
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
407
6.29k
                                code,
408
6.29k
                                scope,
409
6.29k
                            }));
410
                        } else {
411
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$scope"]));
412
                        }
413
                    } else {
414
0
                        return Ok(Bson::JavaScriptCode(code));
415
                    }
416
                }
417
418
0
                "$scope" => {
419
0
                    let scope = visitor.next_value::<Document>()?;
420
0
                    if let Some(key) = visitor.next_key::<String>()? {
421
0
                        if key.as_str() == "$code" {
422
0
                            let code = visitor.next_value::<String>()?;
423
0
                            return Ok(Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
424
0
                                code,
425
0
                                scope,
426
0
                            }));
427
                        } else {
428
0
                            return Err(serde::de::Error::unknown_field(key.as_str(), &["$code"]));
429
                        }
430
                    } else {
431
0
                        return Err(serde::de::Error::missing_field("$code"));
432
                    }
433
                }
434
435
0
                "$timestamp" => {
436
0
                    let ts = visitor.next_value::<extjson::models::TimestampBody>()?;
437
0
                    return Ok(Bson::Timestamp(Timestamp {
438
0
                        time: ts.t,
439
0
                        increment: ts.i,
440
0
                    }));
441
                }
442
443
0
                "$regularExpression" => {
444
0
                    let re = visitor.next_value::<extjson::models::RegexBody>()?;
445
                    return Ok(Bson::RegularExpression(
446
0
                        Regex::from_strings(re.pattern, re.options)
447
0
                            .map_err(serde::de::Error::custom)?,
448
                    ));
449
                }
450
451
0
                "$dbPointer" => {
452
0
                    let dbp = visitor.next_value::<extjson::models::DbPointerBody>()?;
453
                    return Ok(Bson::DbPointer(DbPointer {
454
0
                        id: dbp.id.parse().map_err(serde::de::Error::custom)?,
455
0
                        namespace: dbp.ref_ns,
456
                    }));
457
                }
458
459
0
                "$date" => {
460
0
                    let dt = visitor.next_value::<extjson::models::DateTimeBody>()?;
461
                    return Ok(Bson::DateTime(
462
0
                        extjson::models::DateTime { body: dt }
463
0
                            .parse()
464
0
                            .map_err(serde::de::Error::custom)?,
465
                    ));
466
                }
467
468
0
                "$maxKey" => {
469
0
                    let i = visitor.next_value::<u8>()?;
470
0
                    return extjson::models::MaxKey { value: i }
471
0
                        .parse()
472
0
                        .map_err(serde::de::Error::custom);
473
                }
474
475
0
                "$minKey" => {
476
0
                    let i = visitor.next_value::<u8>()?;
477
0
                    return extjson::models::MinKey { value: i }
478
0
                        .parse()
479
0
                        .map_err(serde::de::Error::custom);
480
                }
481
482
0
                "$undefined" => {
483
0
                    let b = visitor.next_value::<bool>()?;
484
0
                    return extjson::models::Undefined { value: b }
485
0
                        .parse()
486
0
                        .map_err(serde::de::Error::custom);
487
                }
488
489
0
                "$numberDecimal" => {
490
0
                    let string: String = visitor.next_value()?;
491
0
                    return Ok(Bson::Decimal128(string.parse::<Decimal128>().map_err(
492
                        |_| {
493
                            V::Error::invalid_value(
494
                                Unexpected::Str(&string),
495
                                &"decimal128 as a string",
496
                            )
497
                        },
498
0
                    )?));
499
                }
500
501
0
                "$numberDecimalBytes" => {
502
0
                    let bytes = visitor.next_value::<ByteBuf>()?;
503
0
                    return Ok(Bson::Decimal128(Decimal128::deserialize_from_slice(
504
0
                        &bytes,
505
0
                    )?));
506
                }
507
508
0
                k => {
509
0
                    let v = visitor.next_value::<Bson>()?;
510
0
                    doc.insert(k, v);
511
                }
512
            }
513
        }
514
515
0
        Ok(Bson::Document(doc))
516
6.30k
    }
517
518
    #[inline]
519
11.1k
    fn visit_bytes<E>(self, v: &[u8]) -> std::result::Result<Bson, E>
520
11.1k
    where
521
11.1k
        E: serde::de::Error,
522
    {
523
11.1k
        Ok(Bson::Binary(Binary {
524
11.1k
            subtype: BinarySubtype::Generic,
525
11.1k
            bytes: v.to_vec(),
526
11.1k
        }))
527
11.1k
    }
528
529
    #[inline]
530
0
    fn visit_byte_buf<E>(self, v: Vec<u8>) -> std::result::Result<Bson, E>
531
0
    where
532
0
        E: serde::de::Error,
533
    {
534
0
        Ok(Bson::Binary(Binary {
535
0
            subtype: BinarySubtype::Generic,
536
0
            bytes: v,
537
0
        }))
538
0
    }
539
540
    #[inline]
541
0
    fn visit_newtype_struct<D>(self, deserializer: D) -> std::result::Result<Self::Value, D::Error>
542
0
    where
543
0
        D: serde::Deserializer<'de>,
544
    {
545
0
        deserializer.deserialize_any(self)
546
0
    }
547
}
548
549
enum BsonInteger {
550
    Int32(i32),
551
    Int64(i64),
552
}
553
554
0
fn convert_unsigned<E: serde::de::Error>(value: u64) -> std::result::Result<BsonInteger, E> {
555
0
    if let Ok(int32) = i32::try_from(value) {
556
0
        Ok(BsonInteger::Int32(int32))
557
0
    } else if let Ok(int64) = i64::try_from(value) {
558
0
        Ok(BsonInteger::Int64(int64))
559
    } else {
560
0
        Err(serde::de::Error::custom(format!(
561
0
            "cannot represent {} as a signed number",
562
0
            value
563
0
        )))
564
    }
565
0
}
Unexecuted instantiation: bson::de::serde::convert_unsigned::<_>
Unexecuted instantiation: bson::de::serde::convert_unsigned::<bson::error::Error>
Unexecuted instantiation: bson::de::serde::convert_unsigned::<bson::error::Error>
566
567
0
fn convert_unsigned_to_signed<E>(value: u64) -> std::result::Result<Bson, E>
568
0
where
569
0
    E: serde::de::Error,
570
{
571
0
    let bi = convert_unsigned(value)?;
572
0
    match bi {
573
0
        BsonInteger::Int32(i) => Ok(Bson::Int32(i)),
574
0
        BsonInteger::Int64(i) => Ok(Bson::Int64(i)),
575
    }
576
0
}
Unexecuted instantiation: bson::de::serde::convert_unsigned_to_signed::<_>
Unexecuted instantiation: bson::de::serde::convert_unsigned_to_signed::<bson::error::Error>
Unexecuted instantiation: bson::de::serde::convert_unsigned_to_signed::<bson::error::Error>
577
578
0
pub(crate) fn convert_unsigned_to_signed_raw<'a, E>(
579
0
    value: u64,
580
0
) -> std::result::Result<RawBsonRef<'a>, E>
581
0
where
582
0
    E: serde::de::Error,
583
{
584
0
    let bi = convert_unsigned(value)?;
585
0
    match bi {
586
0
        BsonInteger::Int32(i) => Ok(RawBsonRef::Int32(i)),
587
0
        BsonInteger::Int64(i) => Ok(RawBsonRef::Int64(i)),
588
    }
589
0
}
590
591
/// Deserializer for deserializing a [`Bson`] value.
592
pub struct Deserializer {
593
    value: Option<Bson>,
594
    options: DeserializerOptions,
595
}
596
597
/// Options used to configure a [`Deserializer`].
598
#[derive(Debug, Clone, Default)]
599
#[non_exhaustive]
600
pub(crate) struct DeserializerOptions {
601
    /// Whether the [`Deserializer`] should present itself as human readable or not.
602
    /// The default is true. For internal use only.
603
    pub(crate) human_readable: Option<bool>,
604
}
605
606
impl Deserializer {
607
    /// Construct a `Deserializer` with the provided [`Bson`] value.
608
0
    pub fn new(value: Bson) -> Deserializer {
609
0
        Deserializer::new_with_options(value, Default::default())
610
0
    }
611
612
    /// Create a new [`Deserializer`] using the provided options.
613
65.8k
    pub(crate) fn new_with_options(value: Bson, options: DeserializerOptions) -> Self {
614
65.8k
        Deserializer {
615
65.8k
            value: Some(value),
616
65.8k
            options,
617
65.8k
        }
618
65.8k
    }
619
620
65.8k
    fn deserialize_next<'de, V>(mut self, visitor: V, hint: DeserializerHint) -> Result<V::Value>
621
65.8k
    where
622
65.8k
        V: serde::de::Visitor<'de>,
623
    {
624
65.8k
        let value = match self.value.take() {
625
65.8k
            Some(value) => value,
626
0
            None => return Err(Error::end_of_stream()),
627
        };
628
629
65.8k
        let is_rawbson = matches!(hint, DeserializerHint::RawBson);
630
631
65.8k
        if let DeserializerHint::BinarySubtype(expected_subtype) = hint {
632
0
            if let Bson::Binary(ref binary) = value {
633
0
                if binary.subtype != expected_subtype {
634
0
                    return Err(serde::de::Error::custom(format!(
635
0
                        "expected Binary with subtype {:?}, instead got subtype {:?}",
636
0
                        expected_subtype, binary.subtype
637
0
                    )));
638
0
                }
639
0
            }
640
65.8k
        };
641
642
0
        match value {
643
0
            Bson::Double(v) => visitor.visit_f64(v),
644
65.8k
            Bson::String(v) => visitor.visit_string(v),
645
0
            Bson::Array(v) => {
646
0
                let len = v.len();
647
0
                visitor.visit_seq(SeqDeserializer {
648
0
                    iter: v.into_iter(),
649
0
                    options: self.options,
650
0
                    len,
651
0
                })
652
            }
653
0
            Bson::Document(v) => visitor.visit_map(MapDeserializer::new(v, self.options)),
654
0
            Bson::Boolean(v) => visitor.visit_bool(v),
655
0
            Bson::Null => visitor.visit_unit(),
656
0
            Bson::Int32(v) => visitor.visit_i32(v),
657
0
            Bson::Int64(v) => visitor.visit_i64(v),
658
0
            Bson::Binary(b) if b.subtype == BinarySubtype::Generic => {
659
0
                visitor.visit_byte_buf(b.bytes)
660
            }
661
0
            Bson::Decimal128(d) => visitor.visit_map(Decimal128Access::new(d)),
662
            _ => {
663
0
                let doc = value.into_extended_document(is_rawbson);
664
0
                visitor.visit_map(MapDeserializer::new(doc, self.options))
665
            }
666
        }
667
65.8k
    }
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<bson::de::serde::BsonVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<serde_bytes::bytebuf::ByteBufVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<serde_core::de::impls::BoolVisitor>
<bson::de::serde::Deserializer>::deserialize_next::<serde_core::de::impls::StringVisitor>
Line
Count
Source
620
58.4k
    fn deserialize_next<'de, V>(mut self, visitor: V, hint: DeserializerHint) -> Result<V::Value>
621
58.4k
    where
622
58.4k
        V: serde::de::Visitor<'de>,
623
    {
624
58.4k
        let value = match self.value.take() {
625
58.4k
            Some(value) => value,
626
0
            None => return Err(Error::end_of_stream()),
627
        };
628
629
58.4k
        let is_rawbson = matches!(hint, DeserializerHint::RawBson);
630
631
58.4k
        if let DeserializerHint::BinarySubtype(expected_subtype) = hint {
632
0
            if let Bson::Binary(ref binary) = value {
633
0
                if binary.subtype != expected_subtype {
634
0
                    return Err(serde::de::Error::custom(format!(
635
0
                        "expected Binary with subtype {:?}, instead got subtype {:?}",
636
0
                        expected_subtype, binary.subtype
637
0
                    )));
638
0
                }
639
0
            }
640
58.4k
        };
641
642
0
        match value {
643
0
            Bson::Double(v) => visitor.visit_f64(v),
644
58.4k
            Bson::String(v) => visitor.visit_string(v),
645
0
            Bson::Array(v) => {
646
0
                let len = v.len();
647
0
                visitor.visit_seq(SeqDeserializer {
648
0
                    iter: v.into_iter(),
649
0
                    options: self.options,
650
0
                    len,
651
0
                })
652
            }
653
0
            Bson::Document(v) => visitor.visit_map(MapDeserializer::new(v, self.options)),
654
0
            Bson::Boolean(v) => visitor.visit_bool(v),
655
0
            Bson::Null => visitor.visit_unit(),
656
0
            Bson::Int32(v) => visitor.visit_i32(v),
657
0
            Bson::Int64(v) => visitor.visit_i64(v),
658
0
            Bson::Binary(b) if b.subtype == BinarySubtype::Generic => {
659
0
                visitor.visit_byte_buf(b.bytes)
660
            }
661
0
            Bson::Decimal128(d) => visitor.visit_map(Decimal128Access::new(d)),
662
            _ => {
663
0
                let doc = value.into_extended_document(is_rawbson);
664
0
                visitor.visit_map(MapDeserializer::new(doc, self.options))
665
            }
666
        }
667
58.4k
    }
<bson::de::serde::Deserializer>::deserialize_next::<serde::private::de::content::ContentVisitor>
Line
Count
Source
620
7.32k
    fn deserialize_next<'de, V>(mut self, visitor: V, hint: DeserializerHint) -> Result<V::Value>
621
7.32k
    where
622
7.32k
        V: serde::de::Visitor<'de>,
623
    {
624
7.32k
        let value = match self.value.take() {
625
7.32k
            Some(value) => value,
626
0
            None => return Err(Error::end_of_stream()),
627
        };
628
629
7.32k
        let is_rawbson = matches!(hint, DeserializerHint::RawBson);
630
631
7.32k
        if let DeserializerHint::BinarySubtype(expected_subtype) = hint {
632
0
            if let Bson::Binary(ref binary) = value {
633
0
                if binary.subtype != expected_subtype {
634
0
                    return Err(serde::de::Error::custom(format!(
635
0
                        "expected Binary with subtype {:?}, instead got subtype {:?}",
636
0
                        expected_subtype, binary.subtype
637
0
                    )));
638
0
                }
639
0
            }
640
7.32k
        };
641
642
0
        match value {
643
0
            Bson::Double(v) => visitor.visit_f64(v),
644
7.32k
            Bson::String(v) => visitor.visit_string(v),
645
0
            Bson::Array(v) => {
646
0
                let len = v.len();
647
0
                visitor.visit_seq(SeqDeserializer {
648
0
                    iter: v.into_iter(),
649
0
                    options: self.options,
650
0
                    len,
651
0
                })
652
            }
653
0
            Bson::Document(v) => visitor.visit_map(MapDeserializer::new(v, self.options)),
654
0
            Bson::Boolean(v) => visitor.visit_bool(v),
655
0
            Bson::Null => visitor.visit_unit(),
656
0
            Bson::Int32(v) => visitor.visit_i32(v),
657
0
            Bson::Int64(v) => visitor.visit_i64(v),
658
0
            Bson::Binary(b) if b.subtype == BinarySubtype::Generic => {
659
0
                visitor.visit_byte_buf(b.bytes)
660
            }
661
0
            Bson::Decimal128(d) => visitor.visit_map(Decimal128Access::new(d)),
662
            _ => {
663
0
                let doc = value.into_extended_document(is_rawbson);
664
0
                visitor.visit_map(MapDeserializer::new(doc, self.options))
665
            }
666
        }
667
7.32k
    }
<bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::ObjectId as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
620
5
    fn deserialize_next<'de, V>(mut self, visitor: V, hint: DeserializerHint) -> Result<V::Value>
621
5
    where
622
5
        V: serde::de::Visitor<'de>,
623
    {
624
5
        let value = match self.value.take() {
625
5
            Some(value) => value,
626
0
            None => return Err(Error::end_of_stream()),
627
        };
628
629
5
        let is_rawbson = matches!(hint, DeserializerHint::RawBson);
630
631
5
        if let DeserializerHint::BinarySubtype(expected_subtype) = hint {
632
0
            if let Bson::Binary(ref binary) = value {
633
0
                if binary.subtype != expected_subtype {
634
0
                    return Err(serde::de::Error::custom(format!(
635
0
                        "expected Binary with subtype {:?}, instead got subtype {:?}",
636
0
                        expected_subtype, binary.subtype
637
0
                    )));
638
0
                }
639
0
            }
640
5
        };
641
642
0
        match value {
643
0
            Bson::Double(v) => visitor.visit_f64(v),
644
5
            Bson::String(v) => visitor.visit_string(v),
645
0
            Bson::Array(v) => {
646
0
                let len = v.len();
647
0
                visitor.visit_seq(SeqDeserializer {
648
0
                    iter: v.into_iter(),
649
0
                    options: self.options,
650
0
                    len,
651
0
                })
652
            }
653
0
            Bson::Document(v) => visitor.visit_map(MapDeserializer::new(v, self.options)),
654
0
            Bson::Boolean(v) => visitor.visit_bool(v),
655
0
            Bson::Null => visitor.visit_unit(),
656
0
            Bson::Int32(v) => visitor.visit_i32(v),
657
0
            Bson::Int64(v) => visitor.visit_i64(v),
658
0
            Bson::Binary(b) if b.subtype == BinarySubtype::Generic => {
659
0
                visitor.visit_byte_buf(b.bytes)
660
            }
661
0
            Bson::Decimal128(d) => visitor.visit_map(Decimal128Access::new(d)),
662
            _ => {
663
0
                let doc = value.into_extended_document(is_rawbson);
664
0
                visitor.visit_map(MapDeserializer::new(doc, self.options))
665
            }
666
        }
667
5
    }
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::ObjectId as serde_core::de::Deserialize>::deserialize::__Visitor>
<bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::RegexBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
620
3
    fn deserialize_next<'de, V>(mut self, visitor: V, hint: DeserializerHint) -> Result<V::Value>
621
3
    where
622
3
        V: serde::de::Visitor<'de>,
623
    {
624
3
        let value = match self.value.take() {
625
3
            Some(value) => value,
626
0
            None => return Err(Error::end_of_stream()),
627
        };
628
629
3
        let is_rawbson = matches!(hint, DeserializerHint::RawBson);
630
631
3
        if let DeserializerHint::BinarySubtype(expected_subtype) = hint {
632
0
            if let Bson::Binary(ref binary) = value {
633
0
                if binary.subtype != expected_subtype {
634
0
                    return Err(serde::de::Error::custom(format!(
635
0
                        "expected Binary with subtype {:?}, instead got subtype {:?}",
636
0
                        expected_subtype, binary.subtype
637
0
                    )));
638
0
                }
639
0
            }
640
3
        };
641
642
0
        match value {
643
0
            Bson::Double(v) => visitor.visit_f64(v),
644
3
            Bson::String(v) => visitor.visit_string(v),
645
0
            Bson::Array(v) => {
646
0
                let len = v.len();
647
0
                visitor.visit_seq(SeqDeserializer {
648
0
                    iter: v.into_iter(),
649
0
                    options: self.options,
650
0
                    len,
651
0
                })
652
            }
653
0
            Bson::Document(v) => visitor.visit_map(MapDeserializer::new(v, self.options)),
654
0
            Bson::Boolean(v) => visitor.visit_bool(v),
655
0
            Bson::Null => visitor.visit_unit(),
656
0
            Bson::Int32(v) => visitor.visit_i32(v),
657
0
            Bson::Int64(v) => visitor.visit_i64(v),
658
0
            Bson::Binary(b) if b.subtype == BinarySubtype::Generic => {
659
0
                visitor.visit_byte_buf(b.bytes)
660
            }
661
0
            Bson::Decimal128(d) => visitor.visit_map(Decimal128Access::new(d)),
662
            _ => {
663
0
                let doc = value.into_extended_document(is_rawbson);
664
0
                visitor.visit_map(MapDeserializer::new(doc, self.options))
665
            }
666
        }
667
3
    }
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::RegexBody as serde_core::de::Deserialize>::deserialize::__Visitor>
<bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::BinaryBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
620
6
    fn deserialize_next<'de, V>(mut self, visitor: V, hint: DeserializerHint) -> Result<V::Value>
621
6
    where
622
6
        V: serde::de::Visitor<'de>,
623
    {
624
6
        let value = match self.value.take() {
625
6
            Some(value) => value,
626
0
            None => return Err(Error::end_of_stream()),
627
        };
628
629
6
        let is_rawbson = matches!(hint, DeserializerHint::RawBson);
630
631
6
        if let DeserializerHint::BinarySubtype(expected_subtype) = hint {
632
0
            if let Bson::Binary(ref binary) = value {
633
0
                if binary.subtype != expected_subtype {
634
0
                    return Err(serde::de::Error::custom(format!(
635
0
                        "expected Binary with subtype {:?}, instead got subtype {:?}",
636
0
                        expected_subtype, binary.subtype
637
0
                    )));
638
0
                }
639
0
            }
640
6
        };
641
642
0
        match value {
643
0
            Bson::Double(v) => visitor.visit_f64(v),
644
6
            Bson::String(v) => visitor.visit_string(v),
645
0
            Bson::Array(v) => {
646
0
                let len = v.len();
647
0
                visitor.visit_seq(SeqDeserializer {
648
0
                    iter: v.into_iter(),
649
0
                    options: self.options,
650
0
                    len,
651
0
                })
652
            }
653
0
            Bson::Document(v) => visitor.visit_map(MapDeserializer::new(v, self.options)),
654
0
            Bson::Boolean(v) => visitor.visit_bool(v),
655
0
            Bson::Null => visitor.visit_unit(),
656
0
            Bson::Int32(v) => visitor.visit_i32(v),
657
0
            Bson::Int64(v) => visitor.visit_i64(v),
658
0
            Bson::Binary(b) if b.subtype == BinarySubtype::Generic => {
659
0
                visitor.visit_byte_buf(b.bytes)
660
            }
661
0
            Bson::Decimal128(d) => visitor.visit_map(Decimal128Access::new(d)),
662
            _ => {
663
0
                let doc = value.into_extended_document(is_rawbson);
664
0
                visitor.visit_map(MapDeserializer::new(doc, self.options))
665
            }
666
        }
667
6
    }
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::BinaryBody as serde_core::de::Deserialize>::deserialize::__Visitor>
<bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::TimestampBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
620
2
    fn deserialize_next<'de, V>(mut self, visitor: V, hint: DeserializerHint) -> Result<V::Value>
621
2
    where
622
2
        V: serde::de::Visitor<'de>,
623
    {
624
2
        let value = match self.value.take() {
625
2
            Some(value) => value,
626
0
            None => return Err(Error::end_of_stream()),
627
        };
628
629
2
        let is_rawbson = matches!(hint, DeserializerHint::RawBson);
630
631
2
        if let DeserializerHint::BinarySubtype(expected_subtype) = hint {
632
0
            if let Bson::Binary(ref binary) = value {
633
0
                if binary.subtype != expected_subtype {
634
0
                    return Err(serde::de::Error::custom(format!(
635
0
                        "expected Binary with subtype {:?}, instead got subtype {:?}",
636
0
                        expected_subtype, binary.subtype
637
0
                    )));
638
0
                }
639
0
            }
640
2
        };
641
642
0
        match value {
643
0
            Bson::Double(v) => visitor.visit_f64(v),
644
2
            Bson::String(v) => visitor.visit_string(v),
645
0
            Bson::Array(v) => {
646
0
                let len = v.len();
647
0
                visitor.visit_seq(SeqDeserializer {
648
0
                    iter: v.into_iter(),
649
0
                    options: self.options,
650
0
                    len,
651
0
                })
652
            }
653
0
            Bson::Document(v) => visitor.visit_map(MapDeserializer::new(v, self.options)),
654
0
            Bson::Boolean(v) => visitor.visit_bool(v),
655
0
            Bson::Null => visitor.visit_unit(),
656
0
            Bson::Int32(v) => visitor.visit_i32(v),
657
0
            Bson::Int64(v) => visitor.visit_i64(v),
658
0
            Bson::Binary(b) if b.subtype == BinarySubtype::Generic => {
659
0
                visitor.visit_byte_buf(b.bytes)
660
            }
661
0
            Bson::Decimal128(d) => visitor.visit_map(Decimal128Access::new(d)),
662
            _ => {
663
0
                let doc = value.into_extended_document(is_rawbson);
664
0
                visitor.visit_map(MapDeserializer::new(doc, self.options))
665
            }
666
        }
667
2
    }
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::TimestampBody as serde_core::de::Deserialize>::deserialize::__Visitor>
<bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::DbPointerBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
620
4
    fn deserialize_next<'de, V>(mut self, visitor: V, hint: DeserializerHint) -> Result<V::Value>
621
4
    where
622
4
        V: serde::de::Visitor<'de>,
623
    {
624
4
        let value = match self.value.take() {
625
4
            Some(value) => value,
626
0
            None => return Err(Error::end_of_stream()),
627
        };
628
629
4
        let is_rawbson = matches!(hint, DeserializerHint::RawBson);
630
631
4
        if let DeserializerHint::BinarySubtype(expected_subtype) = hint {
632
0
            if let Bson::Binary(ref binary) = value {
633
0
                if binary.subtype != expected_subtype {
634
0
                    return Err(serde::de::Error::custom(format!(
635
0
                        "expected Binary with subtype {:?}, instead got subtype {:?}",
636
0
                        expected_subtype, binary.subtype
637
0
                    )));
638
0
                }
639
0
            }
640
4
        };
641
642
0
        match value {
643
0
            Bson::Double(v) => visitor.visit_f64(v),
644
4
            Bson::String(v) => visitor.visit_string(v),
645
0
            Bson::Array(v) => {
646
0
                let len = v.len();
647
0
                visitor.visit_seq(SeqDeserializer {
648
0
                    iter: v.into_iter(),
649
0
                    options: self.options,
650
0
                    len,
651
0
                })
652
            }
653
0
            Bson::Document(v) => visitor.visit_map(MapDeserializer::new(v, self.options)),
654
0
            Bson::Boolean(v) => visitor.visit_bool(v),
655
0
            Bson::Null => visitor.visit_unit(),
656
0
            Bson::Int32(v) => visitor.visit_i32(v),
657
0
            Bson::Int64(v) => visitor.visit_i64(v),
658
0
            Bson::Binary(b) if b.subtype == BinarySubtype::Generic => {
659
0
                visitor.visit_byte_buf(b.bytes)
660
            }
661
0
            Bson::Decimal128(d) => visitor.visit_map(Decimal128Access::new(d)),
662
            _ => {
663
0
                let doc = value.into_extended_document(is_rawbson);
664
0
                visitor.visit_map(MapDeserializer::new(doc, self.options))
665
            }
666
        }
667
4
    }
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<<bson::extjson::models::DbPointerBody as serde_core::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::BytesOrHexVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<<u32 as serde_core::de::Deserialize>::deserialize::PrimitiveVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer>::deserialize_next::<<u8 as serde_core::de::Deserialize>::deserialize::PrimitiveVisitor>
668
}
669
670
macro_rules! forward_to_deserialize {
671
    ($(
672
        $name:ident ( $( $arg:ident : $ty:ty ),* );
673
    )*) => {
674
        $(
675
            forward_to_deserialize!{
676
                func: $name ( $( $arg: $ty ),* );
677
            }
678
        )*
679
    };
680
681
    (func: deserialize_enum ( $( $arg:ident : $ty:ty ),* );) => {
682
0
        fn deserialize_enum<V>(
683
0
            self,
684
0
            $(_: $ty,)*
685
0
            _visitor: V,
686
0
        ) -> ::std::result::Result<V::Value, Self::Error>
687
0
            where V: ::serde::de::Visitor<'de>
688
        {
689
0
            Err(::serde::de::Error::custom("unexpected Enum"))
690
0
        }
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_enum::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_enum::<_>
691
    };
692
693
    (func: $name:ident ( $( $arg:ident : $ty:ty ),* );) => {
694
        #[inline]
695
58.4k
        fn $name<V>(
696
58.4k
            self,
697
58.4k
            $(_: $ty,)*
698
58.4k
            visitor: V,
699
58.4k
        ) -> ::std::result::Result<V::Value, Self::Error>
700
58.4k
            where V: ::serde::de::Visitor<'de>
701
        {
702
58.4k
            self.deserialize_any(visitor)
703
58.4k
        }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_u8::<<u8 as serde_core::de::Deserialize>::deserialize::PrimitiveVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_map::<bson::de::serde::BsonVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_u32::<<u32 as serde_core::de::Deserialize>::deserialize::PrimitiveVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_bool::<serde_core::de::impls::BoolVisitor>
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_string::<serde_core::de::impls::StringVisitor>
Line
Count
Source
695
58.4k
        fn $name<V>(
696
58.4k
            self,
697
58.4k
            $(_: $ty,)*
698
58.4k
            visitor: V,
699
58.4k
        ) -> ::std::result::Result<V::Value, Self::Error>
700
58.4k
            where V: ::serde::de::Visitor<'de>
701
        {
702
58.4k
            self.deserialize_any(visitor)
703
58.4k
        }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_struct::<<bson::extjson::models::ObjectId as serde_core::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_struct::<<bson::extjson::models::RegexBody as serde_core::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_struct::<<bson::extjson::models::BinaryBody as serde_core::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_struct::<<bson::extjson::models::TimestampBody as serde_core::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_struct::<<bson::extjson::models::DbPointerBody as serde_core::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_byte_buf::<serde_bytes::bytebuf::ByteBufVisitor>
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_identifier::<<bson::extjson::models::ObjectId as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
695
5
        fn $name<V>(
696
5
            self,
697
5
            $(_: $ty,)*
698
5
            visitor: V,
699
5
        ) -> ::std::result::Result<V::Value, Self::Error>
700
5
            where V: ::serde::de::Visitor<'de>
701
        {
702
5
            self.deserialize_any(visitor)
703
5
        }
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_identifier::<<bson::extjson::models::RegexBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
695
3
        fn $name<V>(
696
3
            self,
697
3
            $(_: $ty,)*
698
3
            visitor: V,
699
3
        ) -> ::std::result::Result<V::Value, Self::Error>
700
3
            where V: ::serde::de::Visitor<'de>
701
        {
702
3
            self.deserialize_any(visitor)
703
3
        }
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_identifier::<<bson::extjson::models::BinaryBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
695
6
        fn $name<V>(
696
6
            self,
697
6
            $(_: $ty,)*
698
6
            visitor: V,
699
6
        ) -> ::std::result::Result<V::Value, Self::Error>
700
6
            where V: ::serde::de::Visitor<'de>
701
        {
702
6
            self.deserialize_any(visitor)
703
6
        }
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_identifier::<<bson::extjson::models::TimestampBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
695
2
        fn $name<V>(
696
2
            self,
697
2
            $(_: $ty,)*
698
2
            visitor: V,
699
2
        ) -> ::std::result::Result<V::Value, Self::Error>
700
2
            where V: ::serde::de::Visitor<'de>
701
        {
702
2
            self.deserialize_any(visitor)
703
2
        }
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_identifier::<<bson::extjson::models::DbPointerBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
695
4
        fn $name<V>(
696
4
            self,
697
4
            $(_: $ty,)*
698
4
            visitor: V,
699
4
        ) -> ::std::result::Result<V::Value, Self::Error>
700
4
            where V: ::serde::de::Visitor<'de>
701
        {
702
4
            self.deserialize_any(visitor)
703
4
        }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_i8::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_f32::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_f64::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_i16::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_i32::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_i64::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_seq::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_str::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_u16::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_u64::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_char::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_unit::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_tuple::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_ignored_any::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_unit_struct::<_>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_tuple_struct::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_i8::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_u8::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_f32::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_f64::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_i16::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_i32::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_i64::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_map::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_seq::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_str::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_u16::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_u32::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_u64::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_bool::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_char::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_unit::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_bytes::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_tuple::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_option::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_string::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_struct::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_byte_buf::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_identifier::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_ignored_any::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_unit_struct::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_tuple_struct::<_>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::Deserializer>::deserialize_newtype_struct::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_i8::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_u8::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_f32::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_f64::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_i16::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_i32::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_i64::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_map::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_seq::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_str::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_u16::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_u32::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_u64::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_bool::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_char::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_unit::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_bytes::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_tuple::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_option::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_string::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_struct::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_byte_buf::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_identifier::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_ignored_any::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_unit_struct::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_tuple_struct::<_>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::Deserializer>::deserialize_newtype_struct::<_>
704
    };
705
}
706
707
impl<'de> de::Deserializer<'de> for Deserializer {
708
    type Error = Error;
709
710
    #[allow(deprecated)]
711
0
    fn is_human_readable(&self) -> bool {
712
0
        self.options.human_readable.unwrap_or(true)
713
0
    }
714
715
    #[inline]
716
65.8k
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
717
65.8k
    where
718
65.8k
        V: Visitor<'de>,
719
    {
720
65.8k
        self.deserialize_next(visitor, DeserializerHint::None)
721
65.8k
    }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<bson::de::serde::BsonVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<serde_core::de::impls::BoolVisitor>
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<serde_core::de::impls::StringVisitor>
Line
Count
Source
716
58.4k
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
717
58.4k
    where
718
58.4k
        V: Visitor<'de>,
719
    {
720
58.4k
        self.deserialize_next(visitor, DeserializerHint::None)
721
58.4k
    }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<serde_bytes::bytebuf::ByteBufVisitor>
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<serde::private::de::content::ContentVisitor>
Line
Count
Source
716
7.32k
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
717
7.32k
    where
718
7.32k
        V: Visitor<'de>,
719
    {
720
7.32k
        self.deserialize_next(visitor, DeserializerHint::None)
721
7.32k
    }
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::ObjectId as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
716
5
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
717
5
    where
718
5
        V: Visitor<'de>,
719
    {
720
5
        self.deserialize_next(visitor, DeserializerHint::None)
721
5
    }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::ObjectId as serde_core::de::Deserialize>::deserialize::__Visitor>
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::RegexBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
716
3
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
717
3
    where
718
3
        V: Visitor<'de>,
719
    {
720
3
        self.deserialize_next(visitor, DeserializerHint::None)
721
3
    }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::RegexBody as serde_core::de::Deserialize>::deserialize::__Visitor>
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::BinaryBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
716
6
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
717
6
    where
718
6
        V: Visitor<'de>,
719
    {
720
6
        self.deserialize_next(visitor, DeserializerHint::None)
721
6
    }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::BinaryBody as serde_core::de::Deserialize>::deserialize::__Visitor>
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::TimestampBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
716
2
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
717
2
    where
718
2
        V: Visitor<'de>,
719
    {
720
2
        self.deserialize_next(visitor, DeserializerHint::None)
721
2
    }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::TimestampBody as serde_core::de::Deserialize>::deserialize::__Visitor>
<bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::DbPointerBody as serde_core::de::Deserialize>::deserialize::__FieldVisitor>
Line
Count
Source
716
4
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
717
4
    where
718
4
        V: Visitor<'de>,
719
    {
720
4
        self.deserialize_next(visitor, DeserializerHint::None)
721
4
    }
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<bson::extjson::models::DbPointerBody as serde_core::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex as serde_core::de::Deserialize>::deserialize::BytesOrHexVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<u32 as serde_core::de::Deserialize>::deserialize::PrimitiveVisitor>
Unexecuted instantiation: <bson::de::serde::Deserializer as serde_core::de::Deserializer>::deserialize_any::<<u8 as serde_core::de::Deserialize>::deserialize::PrimitiveVisitor>
722
723
    #[inline]
724
0
    fn deserialize_bytes<V>(self, visitor: V) -> std::result::Result<V::Value, Self::Error>
725
0
    where
726
0
        V: Visitor<'de>,
727
    {
728
0
        match self.value {
729
0
            Some(Bson::ObjectId(oid)) if !self.is_human_readable() => {
730
0
                visitor.visit_bytes(&oid.bytes())
731
            }
732
0
            _ => self.deserialize_any(visitor),
733
        }
734
0
    }
735
736
    #[inline]
737
0
    fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>
738
0
    where
739
0
        V: Visitor<'de>,
740
    {
741
0
        match self.value {
742
0
            Some(Bson::Null) => visitor.visit_none(),
743
0
            Some(_) => visitor.visit_some(self),
744
0
            None => Err(Error::end_of_stream()),
745
        }
746
0
    }
747
748
    #[inline]
749
0
    fn deserialize_enum<V>(
750
0
        mut self,
751
0
        _name: &str,
752
0
        _variants: &'static [&'static str],
753
0
        visitor: V,
754
0
    ) -> Result<V::Value>
755
0
    where
756
0
        V: Visitor<'de>,
757
    {
758
0
        let value = match self.value.take() {
759
0
            Some(Bson::Document(value)) => value,
760
0
            Some(Bson::String(variant)) => {
761
0
                return visitor.visit_enum(EnumDeserializer {
762
0
                    val: Bson::String(variant),
763
0
                    deserializer: VariantDeserializer {
764
0
                        val: None,
765
0
                        options: self.options,
766
0
                    },
767
0
                });
768
            }
769
0
            Some(v) => {
770
0
                return Err(Error::invalid_type(v.as_unexpected(), &"expected an enum"));
771
            }
772
            None => {
773
0
                return Err(Error::end_of_stream());
774
            }
775
        };
776
777
0
        let mut iter = value.into_iter();
778
779
0
        let (variant, value) = match iter.next() {
780
0
            Some(v) => v,
781
            None => {
782
0
                return Err(Error::invalid_value(
783
0
                    Unexpected::Other("empty document"),
784
0
                    &"variant name",
785
0
                ))
786
            }
787
        };
788
789
        // enums are encoded in json as maps with a single key:value pair
790
0
        match iter.next() {
791
0
            Some((k, _)) => Err(Error::invalid_value(
792
0
                Unexpected::Map,
793
0
                &format!("expected map with a single key, got extra key \"{}\"", k).as_str(),
794
0
            )),
795
0
            None => visitor.visit_enum(EnumDeserializer {
796
0
                val: Bson::String(variant),
797
0
                deserializer: VariantDeserializer {
798
0
                    val: Some(value),
799
0
                    options: self.options,
800
0
                },
801
0
            }),
802
        }
803
0
    }
804
805
    #[inline]
806
0
    fn deserialize_newtype_struct<V>(mut self, name: &'static str, visitor: V) -> Result<V::Value>
807
0
    where
808
0
        V: Visitor<'de>,
809
    {
810
0
        match name {
811
0
            UUID_NEWTYPE_NAME => self.deserialize_next(
812
0
                visitor,
813
0
                DeserializerHint::BinarySubtype(BinarySubtype::Uuid),
814
            ),
815
0
            RAW_BSON_NEWTYPE => self.deserialize_next(visitor, DeserializerHint::RawBson),
816
0
            RAW_DOCUMENT_NEWTYPE => {
817
0
                if !matches!(self.value, Some(Bson::Document(_))) {
818
0
                    return Err(serde::de::Error::custom(format!(
819
0
                        "expected raw document, instead got {:?}",
820
0
                        self.value
821
0
                    )));
822
0
                }
823
824
0
                self.deserialize_next(visitor, DeserializerHint::RawBson)
825
            }
826
0
            RAW_ARRAY_NEWTYPE => {
827
0
                if !matches!(self.value, Some(Bson::Array(_))) {
828
0
                    return Err(serde::de::Error::custom(format!(
829
0
                        "expected raw array, instead got {:?}",
830
0
                        self.value
831
0
                    )));
832
0
                }
833
834
0
                self.deserialize_next(visitor, DeserializerHint::RawBson)
835
            }
836
            #[allow(deprecated)]
837
0
            HUMAN_READABLE_NEWTYPE => {
838
0
                self.options.human_readable = Some(true);
839
0
                visitor.visit_newtype_struct(self)
840
            }
841
0
            _ => visitor.visit_newtype_struct(self),
842
        }
843
0
    }
844
845
    forward_to_deserialize! {
846
        deserialize_bool();
847
        deserialize_u8();
848
        deserialize_u16();
849
        deserialize_u32();
850
        deserialize_u64();
851
        deserialize_i8();
852
        deserialize_i16();
853
        deserialize_i32();
854
        deserialize_i64();
855
        deserialize_f32();
856
        deserialize_f64();
857
        deserialize_char();
858
        deserialize_str();
859
        deserialize_string();
860
        deserialize_unit();
861
        deserialize_seq();
862
        deserialize_map();
863
        deserialize_unit_struct(name: &'static str);
864
        deserialize_tuple_struct(name: &'static str, len: usize);
865
        deserialize_struct(name: &'static str, fields: &'static [&'static str]);
866
        deserialize_tuple(len: usize);
867
        deserialize_identifier();
868
        deserialize_ignored_any();
869
        deserialize_byte_buf();
870
    }
871
}
872
873
struct EnumDeserializer {
874
    val: Bson,
875
    deserializer: VariantDeserializer,
876
}
877
878
impl<'de> EnumAccess<'de> for EnumDeserializer {
879
    type Error = Error;
880
    type Variant = VariantDeserializer;
881
0
    fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant)>
882
0
    where
883
0
        V: DeserializeSeed<'de>,
884
    {
885
0
        let dec = Deserializer::new_with_options(self.val, self.deserializer.options.clone());
886
0
        let value = seed.deserialize(dec)?;
887
0
        Ok((value, self.deserializer))
888
0
    }
889
}
890
891
struct VariantDeserializer {
892
    val: Option<Bson>,
893
    options: DeserializerOptions,
894
}
895
896
impl<'de> VariantAccess<'de> for VariantDeserializer {
897
    type Error = Error;
898
899
0
    fn unit_variant(mut self) -> Result<()> {
900
0
        match self.val.take() {
901
0
            None => Ok(()),
902
0
            Some(val) => {
903
0
                Bson::deserialize(Deserializer::new_with_options(val, self.options)).map(|_| ())
904
            }
905
        }
906
0
    }
907
908
0
    fn newtype_variant_seed<T>(mut self, seed: T) -> Result<T::Value>
909
0
    where
910
0
        T: DeserializeSeed<'de>,
911
    {
912
0
        let dec = Deserializer::new_with_options(
913
0
            self.val.take().ok_or_else(Error::end_of_stream)?,
914
0
            self.options,
915
        );
916
0
        seed.deserialize(dec)
917
0
    }
918
919
0
    fn tuple_variant<V>(mut self, _len: usize, visitor: V) -> Result<V::Value>
920
0
    where
921
0
        V: Visitor<'de>,
922
    {
923
0
        match self.val.take().ok_or_else(Error::end_of_stream)? {
924
0
            Bson::Array(fields) => {
925
0
                let de = SeqDeserializer {
926
0
                    len: fields.len(),
927
0
                    iter: fields.into_iter(),
928
0
                    options: self.options,
929
0
                };
930
0
                de.deserialize_any(visitor)
931
            }
932
0
            other => Err(Error::invalid_type(
933
0
                other.as_unexpected(),
934
0
                &"expected a tuple",
935
0
            )),
936
        }
937
0
    }
938
939
0
    fn struct_variant<V>(mut self, _fields: &'static [&'static str], visitor: V) -> Result<V::Value>
940
0
    where
941
0
        V: Visitor<'de>,
942
    {
943
0
        match self.val.take().ok_or_else(Error::end_of_stream)? {
944
0
            Bson::Document(fields) => {
945
0
                let de = MapDeserializer {
946
0
                    len: fields.len(),
947
0
                    iter: fields.into_iter(),
948
0
                    value: None,
949
0
                    options: self.options,
950
0
                };
951
0
                de.deserialize_any(visitor)
952
            }
953
0
            ref other => Err(Error::invalid_type(
954
0
                other.as_unexpected(),
955
0
                &"expected a struct",
956
0
            )),
957
        }
958
0
    }
959
}
960
961
struct SeqDeserializer {
962
    iter: vec::IntoIter<Bson>,
963
    len: usize,
964
    options: DeserializerOptions,
965
}
966
967
impl<'de> de::Deserializer<'de> for SeqDeserializer {
968
    type Error = Error;
969
970
    #[inline]
971
0
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
972
0
    where
973
0
        V: Visitor<'de>,
974
    {
975
0
        if self.len == 0 {
976
0
            visitor.visit_unit()
977
        } else {
978
0
            visitor.visit_seq(self)
979
        }
980
0
    }
981
982
    forward_to_deserialize! {
983
        deserialize_bool();
984
        deserialize_u8();
985
        deserialize_u16();
986
        deserialize_u32();
987
        deserialize_u64();
988
        deserialize_i8();
989
        deserialize_i16();
990
        deserialize_i32();
991
        deserialize_i64();
992
        deserialize_f32();
993
        deserialize_f64();
994
        deserialize_char();
995
        deserialize_str();
996
        deserialize_string();
997
        deserialize_unit();
998
        deserialize_option();
999
        deserialize_seq();
1000
        deserialize_bytes();
1001
        deserialize_map();
1002
        deserialize_unit_struct(name: &'static str);
1003
        deserialize_newtype_struct(name: &'static str);
1004
        deserialize_tuple_struct(name: &'static str, len: usize);
1005
        deserialize_struct(name: &'static str, fields: &'static [&'static str]);
1006
        deserialize_tuple(len: usize);
1007
        deserialize_enum(name: &'static str, variants: &'static [&'static str]);
1008
        deserialize_identifier();
1009
        deserialize_ignored_any();
1010
        deserialize_byte_buf();
1011
    }
1012
}
1013
1014
impl<'de> SeqAccess<'de> for SeqDeserializer {
1015
    type Error = Error;
1016
1017
0
    fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>>
1018
0
    where
1019
0
        T: DeserializeSeed<'de>,
1020
    {
1021
0
        match self.iter.next() {
1022
0
            None => Ok(None),
1023
0
            Some(value) => {
1024
0
                self.len -= 1;
1025
0
                let de = Deserializer::new_with_options(value, self.options.clone());
1026
0
                match seed.deserialize(de) {
1027
0
                    Ok(value) => Ok(Some(value)),
1028
0
                    Err(err) => Err(err),
1029
                }
1030
            }
1031
        }
1032
0
    }
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<bson::bson::Bson>>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<alloc::string::String>>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<bson::extjson::models::ObjectId>>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<u8>>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<u32>>
Unexecuted instantiation: <bson::de::serde::SeqDeserializer as serde_core::de::SeqAccess>::next_element_seed::<serde::private::de::content::ContentVisitor>
1033
1034
0
    fn size_hint(&self) -> Option<usize> {
1035
0
        Some(self.len)
1036
0
    }
1037
}
1038
1039
pub(crate) struct MapDeserializer {
1040
    pub(crate) iter: IntoIter,
1041
    pub(crate) value: Option<Bson>,
1042
    pub(crate) len: usize,
1043
    pub(crate) options: DeserializerOptions,
1044
}
1045
1046
impl MapDeserializer {
1047
32.9k
    pub(crate) fn new(doc: Document, options: impl Into<Option<DeserializerOptions>>) -> Self {
1048
32.9k
        let len = doc.len();
1049
32.9k
        MapDeserializer {
1050
32.9k
            iter: doc.into_iter(),
1051
32.9k
            len,
1052
32.9k
            value: None,
1053
32.9k
            options: options.into().unwrap_or_default(),
1054
32.9k
        }
1055
32.9k
    }
1056
}
1057
1058
impl<'de> MapAccess<'de> for MapDeserializer {
1059
    type Error = Error;
1060
1061
61.3k
    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
1062
61.3k
    where
1063
61.3k
        K: DeserializeSeed<'de>,
1064
    {
1065
61.3k
        match self.iter.next() {
1066
32.9k
            Some((key, value)) => {
1067
32.9k
                self.len -= 1;
1068
32.9k
                self.value = Some(value);
1069
1070
32.9k
                let de = Deserializer::new_with_options(Bson::String(key), self.options.clone());
1071
32.9k
                match seed.deserialize(de) {
1072
32.9k
                    Ok(val) => Ok(Some(val)),
1073
20
                    Err(e) => Err(e),
1074
                }
1075
            }
1076
28.3k
            None => Ok(None),
1077
        }
1078
61.3k
    }
<bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_key_seed::<core::marker::PhantomData<alloc::string::String>>
Line
Count
Source
1061
53.9k
    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
1062
53.9k
    where
1063
53.9k
        K: DeserializeSeed<'de>,
1064
    {
1065
53.9k
        match self.iter.next() {
1066
29.2k
            Some((key, value)) => {
1067
29.2k
                self.len -= 1;
1068
29.2k
                self.value = Some(value);
1069
1070
29.2k
                let de = Deserializer::new_with_options(Bson::String(key), self.options.clone());
1071
29.2k
                match seed.deserialize(de) {
1072
29.2k
                    Ok(val) => Ok(Some(val)),
1073
0
                    Err(e) => Err(e),
1074
                }
1075
            }
1076
24.7k
            None => Ok(None),
1077
        }
1078
53.9k
    }
<bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<bson::extjson::models::ObjectId as serde_core::de::Deserialize>::deserialize::__Field>>
Line
Count
Source
1061
5
    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
1062
5
    where
1063
5
        K: DeserializeSeed<'de>,
1064
    {
1065
5
        match self.iter.next() {
1066
5
            Some((key, value)) => {
1067
5
                self.len -= 1;
1068
5
                self.value = Some(value);
1069
1070
5
                let de = Deserializer::new_with_options(Bson::String(key), self.options.clone());
1071
5
                match seed.deserialize(de) {
1072
0
                    Ok(val) => Ok(Some(val)),
1073
5
                    Err(e) => Err(e),
1074
                }
1075
            }
1076
0
            None => Ok(None),
1077
        }
1078
5
    }
<bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<bson::extjson::models::RegexBody as serde_core::de::Deserialize>::deserialize::__Field>>
Line
Count
Source
1061
3
    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
1062
3
    where
1063
3
        K: DeserializeSeed<'de>,
1064
    {
1065
3
        match self.iter.next() {
1066
3
            Some((key, value)) => {
1067
3
                self.len -= 1;
1068
3
                self.value = Some(value);
1069
1070
3
                let de = Deserializer::new_with_options(Bson::String(key), self.options.clone());
1071
3
                match seed.deserialize(de) {
1072
0
                    Ok(val) => Ok(Some(val)),
1073
3
                    Err(e) => Err(e),
1074
                }
1075
            }
1076
0
            None => Ok(None),
1077
        }
1078
3
    }
<bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<bson::extjson::models::BinaryBody as serde_core::de::Deserialize>::deserialize::__Field>>
Line
Count
Source
1061
6
    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
1062
6
    where
1063
6
        K: DeserializeSeed<'de>,
1064
    {
1065
6
        match self.iter.next() {
1066
6
            Some((key, value)) => {
1067
6
                self.len -= 1;
1068
6
                self.value = Some(value);
1069
1070
6
                let de = Deserializer::new_with_options(Bson::String(key), self.options.clone());
1071
6
                match seed.deserialize(de) {
1072
0
                    Ok(val) => Ok(Some(val)),
1073
6
                    Err(e) => Err(e),
1074
                }
1075
            }
1076
0
            None => Ok(None),
1077
        }
1078
6
    }
<bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<bson::extjson::models::TimestampBody as serde_core::de::Deserialize>::deserialize::__Field>>
Line
Count
Source
1061
2
    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
1062
2
    where
1063
2
        K: DeserializeSeed<'de>,
1064
    {
1065
2
        match self.iter.next() {
1066
2
            Some((key, value)) => {
1067
2
                self.len -= 1;
1068
2
                self.value = Some(value);
1069
1070
2
                let de = Deserializer::new_with_options(Bson::String(key), self.options.clone());
1071
2
                match seed.deserialize(de) {
1072
0
                    Ok(val) => Ok(Some(val)),
1073
2
                    Err(e) => Err(e),
1074
                }
1075
            }
1076
0
            None => Ok(None),
1077
        }
1078
2
    }
<bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<bson::extjson::models::DbPointerBody as serde_core::de::Deserialize>::deserialize::__Field>>
Line
Count
Source
1061
4
    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
1062
4
    where
1063
4
        K: DeserializeSeed<'de>,
1064
    {
1065
4
        match self.iter.next() {
1066
4
            Some((key, value)) => {
1067
4
                self.len -= 1;
1068
4
                self.value = Some(value);
1069
1070
4
                let de = Deserializer::new_with_options(Bson::String(key), self.options.clone());
1071
4
                match seed.deserialize(de) {
1072
0
                    Ok(val) => Ok(Some(val)),
1073
4
                    Err(e) => Err(e),
1074
                }
1075
            }
1076
0
            None => Ok(None),
1077
        }
1078
4
    }
<bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_key_seed::<serde::private::de::content::ContentVisitor>
Line
Count
Source
1061
7.32k
    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
1062
7.32k
    where
1063
7.32k
        K: DeserializeSeed<'de>,
1064
    {
1065
7.32k
        match self.iter.next() {
1066
3.66k
            Some((key, value)) => {
1067
3.66k
                self.len -= 1;
1068
3.66k
                self.value = Some(value);
1069
1070
3.66k
                let de = Deserializer::new_with_options(Bson::String(key), self.options.clone());
1071
3.66k
                match seed.deserialize(de) {
1072
3.66k
                    Ok(val) => Ok(Some(val)),
1073
0
                    Err(e) => Err(e),
1074
                }
1075
            }
1076
3.66k
            None => Ok(None),
1077
        }
1078
7.32k
    }
1079
1080
32.9k
    fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value>
1081
32.9k
    where
1082
32.9k
        V: DeserializeSeed<'de>,
1083
    {
1084
32.9k
        let value = self.value.take().ok_or_else(Error::end_of_stream)?;
1085
32.9k
        let de = Deserializer::new_with_options(value, self.options.clone());
1086
32.9k
        seed.deserialize(de)
1087
32.9k
    }
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bson::bson::Bson>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bson::document::Document>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<serde_bytes::bytebuf::ByteBuf>>
<bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<alloc::string::String>>
Line
Count
Source
1080
29.2k
    fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value>
1081
29.2k
    where
1082
29.2k
        V: DeserializeSeed<'de>,
1083
    {
1084
29.2k
        let value = self.value.take().ok_or_else(Error::end_of_stream)?;
1085
29.2k
        let de = Deserializer::new_with_options(value, self.options.clone());
1086
29.2k
        seed.deserialize(de)
1087
29.2k
    }
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bson::extjson::models::BinaryBody>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bson::extjson::models::DateTimeBody>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bson::extjson::models::DbPointerBody>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bson::extjson::models::TimestampBody>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bson::extjson::models::ObjectId>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bson::extjson::models::RegexBody>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<<bson::de::serde::BsonVisitor as serde_core::de::Visitor>::visit_map::BytesOrHex>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bool>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<u8>>
Unexecuted instantiation: <bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<core::marker::PhantomData<u32>>
<bson::de::serde::MapDeserializer as serde_core::de::MapAccess>::next_value_seed::<serde::private::de::content::ContentVisitor>
Line
Count
Source
1080
3.66k
    fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value>
1081
3.66k
    where
1082
3.66k
        V: DeserializeSeed<'de>,
1083
    {
1084
3.66k
        let value = self.value.take().ok_or_else(Error::end_of_stream)?;
1085
3.66k
        let de = Deserializer::new_with_options(value, self.options.clone());
1086
3.66k
        seed.deserialize(de)
1087
3.66k
    }
1088
1089
3.66k
    fn size_hint(&self) -> Option<usize> {
1090
3.66k
        Some(self.len)
1091
3.66k
    }
1092
}
1093
1094
impl<'de> de::Deserializer<'de> for MapDeserializer {
1095
    type Error = Error;
1096
1097
    #[inline]
1098
0
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
1099
0
    where
1100
0
        V: Visitor<'de>,
1101
    {
1102
0
        visitor.visit_map(self)
1103
0
    }
1104
1105
    forward_to_deserialize! {
1106
        deserialize_bool();
1107
        deserialize_u8();
1108
        deserialize_u16();
1109
        deserialize_u32();
1110
        deserialize_u64();
1111
        deserialize_i8();
1112
        deserialize_i16();
1113
        deserialize_i32();
1114
        deserialize_i64();
1115
        deserialize_f32();
1116
        deserialize_f64();
1117
        deserialize_char();
1118
        deserialize_str();
1119
        deserialize_string();
1120
        deserialize_unit();
1121
        deserialize_option();
1122
        deserialize_seq();
1123
        deserialize_bytes();
1124
        deserialize_map();
1125
        deserialize_unit_struct(name: &'static str);
1126
        deserialize_newtype_struct(name: &'static str);
1127
        deserialize_tuple_struct(name: &'static str, len: usize);
1128
        deserialize_struct(name: &'static str, fields: &'static [&'static str]);
1129
        deserialize_tuple(len: usize);
1130
        deserialize_enum(name: &'static str, variants: &'static [&'static str]);
1131
        deserialize_identifier();
1132
        deserialize_ignored_any();
1133
        deserialize_byte_buf();
1134
    }
1135
}
1136
1137
impl<'de> Deserialize<'de> for Timestamp {
1138
0
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1139
0
    where
1140
0
        D: de::Deserializer<'de>,
1141
    {
1142
0
        match Bson::deserialize(deserializer)? {
1143
0
            Bson::Timestamp(timestamp) => Ok(timestamp),
1144
0
            _ => Err(serde::de::Error::custom("expecting Timestamp")),
1145
        }
1146
0
    }
1147
}
1148
1149
impl<'de> Deserialize<'de> for Regex {
1150
0
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1151
0
    where
1152
0
        D: de::Deserializer<'de>,
1153
    {
1154
0
        match Bson::deserialize(deserializer)? {
1155
0
            Bson::RegularExpression(regex) => Ok(regex),
1156
0
            _ => Err(serde::de::Error::custom("expecting Regex")),
1157
        }
1158
0
    }
1159
}
1160
1161
impl<'de> Deserialize<'de> for JavaScriptCodeWithScope {
1162
0
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1163
0
    where
1164
0
        D: de::Deserializer<'de>,
1165
    {
1166
0
        match Bson::deserialize(deserializer)? {
1167
0
            Bson::JavaScriptCodeWithScope(code_with_scope) => Ok(code_with_scope),
1168
0
            _ => Err(serde::de::Error::custom(
1169
0
                "expecting JavaScriptCodeWithScope",
1170
0
            )),
1171
        }
1172
0
    }
1173
}
1174
1175
impl<'de> Deserialize<'de> for Binary {
1176
0
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1177
0
    where
1178
0
        D: de::Deserializer<'de>,
1179
    {
1180
0
        match Bson::deserialize(deserializer)? {
1181
0
            Bson::Binary(binary) => Ok(binary),
1182
0
            d => Err(serde::de::Error::custom(format!(
1183
0
                "expecting Binary but got {:?} instead",
1184
0
                d
1185
0
            ))),
1186
        }
1187
0
    }
1188
}
1189
1190
impl<'de> Deserialize<'de> for Decimal128 {
1191
0
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1192
0
    where
1193
0
        D: de::Deserializer<'de>,
1194
    {
1195
0
        match Bson::deserialize(deserializer)? {
1196
0
            Bson::Decimal128(d128) => Ok(d128),
1197
0
            o => Err(serde::de::Error::custom(format!(
1198
0
                "expecting Decimal128, got {:?}",
1199
0
                o
1200
0
            ))),
1201
        }
1202
0
    }
1203
}
1204
1205
impl<'de> Deserialize<'de> for DateTime {
1206
0
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1207
0
    where
1208
0
        D: de::Deserializer<'de>,
1209
    {
1210
0
        match Bson::deserialize(deserializer)? {
1211
0
            Bson::DateTime(dt) => Ok(dt),
1212
0
            _ => Err(serde::de::Error::custom("expecting DateTime")),
1213
        }
1214
0
    }
1215
}
1216
1217
impl<'de> Deserialize<'de> for DbPointer {
1218
0
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1219
0
    where
1220
0
        D: de::Deserializer<'de>,
1221
    {
1222
0
        match Bson::deserialize(deserializer)? {
1223
0
            Bson::DbPointer(db_pointer) => Ok(db_pointer),
1224
0
            _ => Err(serde::de::Error::custom("expecting DbPointer")),
1225
        }
1226
0
    }
1227
}