Skip to content

Commit cd83266

Browse files
authored
RUST-1887 Update driver for bson append changes (#1390)
1 parent e18a7a1 commit cd83266

File tree

7 files changed

+59
-1
lines changed

7 files changed

+59
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bson_compat.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub(crate) trait RawDocumentBufExt {
2+
fn append_ref<'a>(
3+
&mut self,
4+
key: impl AsRef<str>,
5+
value: impl Into<crate::bson::raw::RawBsonRef<'a>>,
6+
);
7+
}
8+
9+
impl RawDocumentBufExt for crate::bson::RawDocumentBuf {
10+
fn append_ref<'a>(
11+
&mut self,
12+
key: impl AsRef<str>,
13+
value: impl Into<crate::bson::raw::RawBsonRef<'a>>,
14+
) {
15+
self.append(key, value)
16+
}
17+
}

src/bson_util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ use crate::{
2222
runtime::SyncLittleEndianRead,
2323
};
2424

25+
#[cfg(feature = "bson-3")]
26+
use crate::bson_compat::RawDocumentBufExt as _;
27+
2528
/// Coerce numeric types into an `i64` if it would be lossless to do so. If this Bson is not numeric
2629
/// or the conversion would be lossy (e.g. 1.5 -> 1), this returns `None`.
2730
#[allow(clippy::cast_possible_truncation)]

src/cmap/establish/handshake.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ impl From<&OsMetadata> for RawBson {
121121
}
122122
}
123123

124+
#[cfg(feature = "bson-3")]
125+
impl crate::bson::raw::BindRawBsonRef for &OsMetadata {
126+
fn bind<F, R>(self, f: F) -> R
127+
where
128+
F: for<'a> FnOnce(bson3::RawBsonRef<'a>) -> R,
129+
{
130+
let raw: RawBson = self.into();
131+
raw.bind(f)
132+
}
133+
}
134+
124135
impl From<&RuntimeEnvironment> for RawBson {
125136
fn from(env: &RuntimeEnvironment) -> Self {
126137
let RuntimeEnvironment {
@@ -158,6 +169,17 @@ impl From<&RuntimeEnvironment> for RawBson {
158169
}
159170
}
160171

172+
#[cfg(feature = "bson-3")]
173+
impl crate::bson::raw::BindRawBsonRef for &RuntimeEnvironment {
174+
fn bind<F, R>(self, f: F) -> R
175+
where
176+
F: for<'a> FnOnce(bson3::RawBsonRef<'a>) -> R,
177+
{
178+
let raw: RawBson = self.into();
179+
raw.bind(f)
180+
}
181+
}
182+
161183
impl RuntimeEnvironment {
162184
pub(crate) const UNSET: Self = RuntimeEnvironment {
163185
name: None,

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub mod options;
2121
pub use ::mongocrypt;
2222

2323
pub mod action;
24+
#[cfg(feature = "bson-3")]
25+
pub(crate) mod bson_compat;
2426
mod bson_util;
2527
pub mod change_stream;
2628
pub(crate) mod checked;

src/operation/update.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ use crate::{
1313

1414
use super::ExecutionContext;
1515

16+
#[cfg(feature = "bson-3")]
17+
use crate::bson_compat::RawDocumentBufExt as _;
18+
1619
#[derive(Clone, Debug)]
1720
pub(crate) enum UpdateOrReplace {
1821
UpdateModifications(UpdateModifications),

src/sdam/description/server.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ impl From<TopologyVersion> for RawBson {
111111
}
112112
}
113113

114+
#[cfg(feature = "bson-3")]
115+
impl crate::bson::raw::BindRawBsonRef for TopologyVersion {
116+
fn bind<F, R>(self, f: F) -> R
117+
where
118+
F: for<'a> FnOnce(bson3::RawBsonRef<'a>) -> R,
119+
{
120+
let raw: RawBson = self.into();
121+
raw.bind(f)
122+
}
123+
}
124+
114125
/// A description of the most up-to-date information known about a server.
115126
#[derive(Debug, Clone, Serialize)]
116127
pub(crate) struct ServerDescription {

0 commit comments

Comments
 (0)