Skip to content

Commit

Permalink
rename macro
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelatkinson committed Feb 21, 2024
1 parent 1d633b7 commit 6376b32
Show file tree
Hide file tree
Showing 26 changed files with 65 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ impl<'a, O> OperationResponse<'a, O> {
}
}

macro_rules! sync {
macro_rules! handle_response_sync {
($result:block) => {
let result = || $result;
OperationResponse::Sync(result())
};
}
use sync;
use handle_response_sync;

/// A trait modeling the behavior of a server side operation.
///
Expand Down
4 changes: 2 additions & 2 deletions src/operation/abort_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
ClientSession,
};

use super::{sync, OperationResponse, OperationWithDefaults, WriteConcernOnlyBody};
use super::{handle_response_sync, OperationResponse, OperationWithDefaults, WriteConcernOnlyBody};

pub(crate) struct AbortTransaction {
write_concern: Option<WriteConcern>,
Expand Down Expand Up @@ -56,7 +56,7 @@ impl OperationWithDefaults for AbortTransaction {
_description: &'a StreamDescription,
_session: Option<&'a mut ClientSession>,
) -> OperationResponse<'a, Self::O> {
sync! {{
handle_response_sync! {{
let response: WriteConcernOnlyBody = response.body()?;
response.validate()
}}
Expand Down
4 changes: 2 additions & 2 deletions src/operation/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
};

use super::{
sync,
handle_response_sync,
CursorBody,
OperationResponse,
OperationWithDefaults,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl OperationWithDefaults for Aggregate {
description: &'a StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let cursor_response: CursorBody = response.body()?;

if self.is_out_or_merge() {
Expand Down
4 changes: 2 additions & 2 deletions src/operation/aggregate/change_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
ClientSession,
};

use super::{sync, Aggregate, OperationResponse};
use super::{handle_response_sync, Aggregate, OperationResponse};

pub(crate) struct ChangeStreamAggregate {
inner: Aggregate,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl OperationWithDefaults for ChangeStreamAggregate {
description: &'a StreamDescription,
session: Option<&'a mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let op_time = response
.raw_body()
.get("operationTime")?
Expand Down
4 changes: 2 additions & 2 deletions src/operation/commit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
ClientSession,
};

use super::{sync, OperationResponse, WriteConcernOnlyBody};
use super::{handle_response_sync, OperationResponse, WriteConcernOnlyBody};

pub(crate) struct CommitTransaction {
options: Option<TransactionOptions>,
Expand Down Expand Up @@ -49,7 +49,7 @@ impl OperationWithDefaults for CommitTransaction {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: WriteConcernOnlyBody = response.body()?;
response.validate()
}}
Expand Down
4 changes: 2 additions & 2 deletions src/operation/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
ClientSession,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

pub(crate) struct Count {
ns: Namespace,
Expand Down Expand Up @@ -51,7 +51,7 @@ impl OperationWithDefaults for Count {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response_body: ResponseBody = response.body()?;
Ok(response_body.n)
}}
Expand Down
10 changes: 8 additions & 2 deletions src/operation/count_documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ use crate::{
Namespace,
};

use super::{sync, OperationResponse, OperationWithDefaults, Retryability, SingleCursorResult};
use super::{
handle_response_sync,
OperationResponse,
OperationWithDefaults,
Retryability,
SingleCursorResult,
};

pub(crate) struct CountDocuments {
aggregate: Aggregate,
Expand Down Expand Up @@ -95,7 +101,7 @@ impl OperationWithDefaults for CountDocuments {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: SingleCursorResult<Body> = response.body()?;
Ok(response.0.map(|r| r.n).unwrap_or(0))
}}
Expand Down
4 changes: 2 additions & 2 deletions src/operation/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
Namespace,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

#[derive(Debug)]
pub(crate) struct Create {
Expand Down Expand Up @@ -56,7 +56,7 @@ impl OperationWithDefaults for Create {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: WriteConcernOnlyBody = response.body()?;
response.validate()
}}
Expand Down
4 changes: 2 additions & 2 deletions src/operation/create_indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
Namespace,
};

use super::{sync, OperationResponse, WriteConcernOnlyBody};
use super::{handle_response_sync, OperationResponse, WriteConcernOnlyBody};

#[derive(Debug)]
pub(crate) struct CreateIndexes {
Expand Down Expand Up @@ -77,7 +77,7 @@ impl OperationWithDefaults for CreateIndexes {
_description: &'a StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: WriteConcernOnlyBody = response.body()?;
response.validate()?;
let index_names = self.indexes.iter().filter_map(|i| i.get_name()).collect();
Expand Down
4 changes: 2 additions & 2 deletions src/operation/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
ClientSession,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

#[derive(Debug)]
pub(crate) struct Delete {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl OperationWithDefaults for Delete {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: WriteResponseBody = response.body()?;
response.validate().map_err(convert_bulk_errors)?;

Expand Down
4 changes: 2 additions & 2 deletions src/operation/distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
ClientSession,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

pub(crate) struct Distinct {
ns: Namespace,
Expand Down Expand Up @@ -77,7 +77,7 @@ impl OperationWithDefaults for Distinct {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: Response = response.body()?;
Ok(response.values)
}}
Expand Down
4 changes: 2 additions & 2 deletions src/operation/drop_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
Namespace,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

#[derive(Debug)]
pub(crate) struct DropCollection {
Expand Down Expand Up @@ -56,7 +56,7 @@ impl OperationWithDefaults for DropCollection {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: WriteConcernOnlyBody = response.body()?;
response.validate()
}}
Expand Down
4 changes: 2 additions & 2 deletions src/operation/drop_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
ClientSession,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

#[derive(Debug)]
pub(crate) struct DropDatabase {
Expand Down Expand Up @@ -63,7 +63,7 @@ impl OperationWithDefaults for DropDatabase {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: WriteConcernOnlyBody = response.body()?;
response.validate()
}}
Expand Down
4 changes: 2 additions & 2 deletions src/operation/drop_indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
Namespace,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

pub(crate) struct DropIndexes {
ns: Namespace,
Expand Down Expand Up @@ -49,7 +49,7 @@ impl OperationWithDefaults for DropIndexes {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{ Ok(()) }}
handle_response_sync! {{ Ok(()) }}
}

fn write_concern(&self) -> Option<&WriteConcern> {
Expand Down
4 changes: 2 additions & 2 deletions src/operation/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
Namespace,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

#[derive(Debug)]
pub(crate) struct Find {
Expand Down Expand Up @@ -112,7 +112,7 @@ impl OperationWithDefaults for Find {
description: &'a StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: CursorBody = response.body()?;

// The comment should only be propagated to getMore calls on 4.4+.
Expand Down
4 changes: 2 additions & 2 deletions src/operation/find_and_modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
ClientSession,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

pub(crate) struct FindAndModify<'a, R, T: DeserializeOwned> {
ns: Namespace,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<'a, R: Serialize, T: DeserializeOwned> OperationWithDefaults for FindAndMod
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
#[derive(Debug, Deserialize)]
pub(crate) struct Response {
value: RawBson,
Expand Down
4 changes: 2 additions & 2 deletions src/operation/get_more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
Namespace,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

#[derive(Debug)]
pub(crate) struct GetMore<'conn> {
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<'conn> OperationWithDefaults for GetMore<'conn> {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: GetMoreResponseBody = response.body()?;

Ok(GetMoreResult {
Expand Down
9 changes: 7 additions & 2 deletions src/operation/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ use crate::{
Namespace,
};

use super::{sync, OperationResponse, COMMAND_OVERHEAD_SIZE, MAX_ENCRYPTED_WRITE_SIZE};
use super::{
handle_response_sync,
OperationResponse,
COMMAND_OVERHEAD_SIZE,
MAX_ENCRYPTED_WRITE_SIZE,
};

#[derive(Debug)]
pub(crate) struct Insert<'a, T> {
Expand Down Expand Up @@ -129,7 +134,7 @@ impl<'a, T: Serialize> OperationWithDefaults for Insert<'a, T> {
_description: &'b StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: WriteResponseBody = raw_response.body_utf8_lossy()?;

let mut map = HashMap::new();
Expand Down
4 changes: 2 additions & 2 deletions src/operation/list_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
ClientSession,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

#[derive(Debug)]
pub(crate) struct ListCollections {
Expand Down Expand Up @@ -66,7 +66,7 @@ impl OperationWithDefaults for ListCollections {
description: &'a StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: CursorBody = raw_response.body()?;
Ok(CursorSpecification::new(
response.cursor,
Expand Down
4 changes: 2 additions & 2 deletions src/operation/list_databases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
ClientSession,
};

use super::{sync, OperationResponse};
use super::{handle_response_sync, OperationResponse};

#[derive(Debug)]
pub(crate) struct ListDatabases {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl OperationWithDefaults for ListDatabases {
_description: &StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: Response = raw_response.body()?;
Ok(response.databases)
}}
Expand Down
4 changes: 2 additions & 2 deletions src/operation/list_indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
Namespace,
};

use super::{sync, CursorBody, OperationResponse, Retryability};
use super::{handle_response_sync, CursorBody, OperationResponse, Retryability};

pub(crate) struct ListIndexes {
ns: Namespace,
Expand Down Expand Up @@ -51,7 +51,7 @@ impl OperationWithDefaults for ListIndexes {
description: &'a StreamDescription,
_session: Option<&mut ClientSession>,
) -> OperationResponse<'static, Self::O> {
sync! {{
handle_response_sync! {{
let response: CursorBody = raw_response.body()?;
Ok(CursorSpecification::new(
response.cursor,
Expand Down
Loading

0 comments on commit 6376b32

Please sign in to comment.