Skip to content

Commit f9597f7

Browse files
committed
fix Message::with_command, rename deprecation_errors
1 parent 4f61027 commit f9597f7

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/client/options/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ impl<'de> Deserialize<'de> for ServerApiVersion {
339339
#[serde_with::skip_serializing_none]
340340
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, TypedBuilder)]
341341
#[builder(field_defaults(setter(into)))]
342-
#[serde(rename_all = "camelCase")]
343342
#[non_exhaustive]
344343
pub struct ServerApi {
345344
/// The declared API version.
@@ -356,6 +355,7 @@ pub struct ServerApi {
356355
/// deprecated from the declared API version is used.
357356
/// Note that at the time of this writing, no deprecations in version 1 exist.
358357
#[builder(default)]
358+
#[serde(rename = "apiDeprecationErrors")]
359359
pub deprecation_errors: Option<bool>,
360360
}
361361

src/cmap/conn/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl Connection {
267267
command: RawCommand,
268268
request_id: impl Into<Option<i32>>,
269269
) -> Result<RawCommandResponse> {
270-
let message = Message::with_raw_command(command, request_id.into())?;
270+
let message = Message::with_raw_command(command, request_id.into());
271271
self.send_message(message).await
272272
}
273273

src/cmap/conn/wire/message.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,29 @@ impl Message {
3333
/// Creates a `Message` from a given `Command`.
3434
///
3535
/// Note that `response_to` will need to be set manually.
36-
pub(crate) fn with_command(mut command: Command, request_id: Option<i32>) -> Result<Self> {
37-
command.body.insert("$db", command.target_db);
38-
39-
let mut bytes = Vec::new();
40-
command.body.to_writer(&mut bytes)?;
41-
Ok(Self {
42-
response_to: 0,
43-
flags: MessageFlags::empty(),
44-
sections: vec![MessageSection::Document(bytes)],
45-
checksum: None,
36+
pub(crate) fn with_command(command: Command, request_id: Option<i32>) -> Result<Self> {
37+
let bytes = bson::to_vec(&command)?;
38+
Ok(Self::with_raw_command(
39+
RawCommand {
40+
bytes,
41+
target_db: command.target_db,
42+
name: command.name,
43+
},
4644
request_id,
47-
})
45+
))
4846
}
4947

5048
/// Creates a `Message` from a given `Command`.
5149
///
5250
/// Note that `response_to` will need to be set manually.
53-
pub(crate) fn with_raw_command(command: RawCommand, request_id: Option<i32>) -> Result<Self> {
54-
Ok(Self {
51+
pub(crate) fn with_raw_command(command: RawCommand, request_id: Option<i32>) -> Self {
52+
Self {
5553
response_to: 0,
5654
flags: MessageFlags::empty(),
5755
sections: vec![MessageSection::Document(command.bytes)],
5856
checksum: None,
5957
request_id,
60-
})
58+
}
6159
}
6260

6361
/// Gets the first document contained in this Message.

0 commit comments

Comments
 (0)