Skip to content

Commit f9b1aa4

Browse files
authored
RUST-738 Remove Arc wrapper around BSON errors (#329)
This also updates the driver to track the master branch of the bson repo.
1 parent 9e8782b commit f9b1aa4

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bson-u2i = ["bson/u2i"]
3434
async-trait = "0.1.42"
3535
base64 = "0.13.0"
3636
bitflags = "1.1.0"
37-
bson = "1.2.0"
37+
bson = { git = "https://github.com/mongodb/bson-rust" }
3838
chrono = "0.4.7"
3939
derivative = "2.1.1"
4040
futures = "0.3.5"

src/cursor/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ type ImplicitSessionCursor = GenericCursor<ImplicitSessionGetMoreProvider>;
151151

152152
struct ImplicitSessionGetMoreResult {
153153
get_more_result: Result<GetMoreResult>,
154-
session: Option<ClientSession>,
154+
session: Option<Box<ClientSession>>,
155155
}
156156

157157
impl GetMoreProviderResult for ImplicitSessionGetMoreResult {
158-
type Session = Option<ClientSession>;
158+
type Session = Option<Box<ClientSession>>;
159159

160160
fn as_ref(&self) -> std::result::Result<&GetMoreResult, &Error> {
161161
self.get_more_result.as_ref()
@@ -170,7 +170,7 @@ impl GetMoreProviderResult for ImplicitSessionGetMoreResult {
170170
/// This is to be used with cursors associated with implicit sessions.
171171
enum ImplicitSessionGetMoreProvider {
172172
Executing(BoxFuture<'static, ImplicitSessionGetMoreResult>),
173-
Idle(Option<ClientSession>),
173+
Idle(Option<Box<ClientSession>>),
174174
Done,
175175
}
176176

@@ -179,7 +179,7 @@ impl ImplicitSessionGetMoreProvider {
179179
if spec.id() == 0 {
180180
Self::Done
181181
} else {
182-
Self::Idle(session)
182+
Self::Idle(session.map(Box::new))
183183
}
184184
}
185185
}
@@ -195,7 +195,7 @@ impl GetMoreProvider for ImplicitSessionGetMoreProvider {
195195
}
196196
}
197197

198-
fn clear_execution(&mut self, session: Option<ClientSession>, exhausted: bool) {
198+
fn clear_execution(&mut self, session: Option<Box<ClientSession>>, exhausted: bool) {
199199
// If cursor is exhausted, immediately return implicit session to the pool.
200200
if exhausted {
201201
*self = Self::Done;
@@ -209,8 +209,9 @@ impl GetMoreProvider for ImplicitSessionGetMoreProvider {
209209
Self::Idle(mut session) => {
210210
let future = Box::pin(async move {
211211
let get_more = GetMore::new(info);
212-
let get_more_result =
213-
client.execute_operation(get_more, session.as_mut()).await;
212+
let get_more_result = client
213+
.execute_operation(get_more, session.as_mut().map(|b| b.as_mut()))
214+
.await;
214215
ImplicitSessionGetMoreResult {
215216
get_more_result,
216217
session,

src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ where
205205

206206
impl From<bson::de::Error> for ErrorKind {
207207
fn from(err: bson::de::Error) -> Self {
208-
Self::BsonDecode(Arc::new(err))
208+
Self::BsonDecode(err)
209209
}
210210
}
211211

212212
impl From<bson::ser::Error> for ErrorKind {
213213
fn from(err: bson::ser::Error) -> Self {
214-
Self::BsonEncode(Arc::new(err))
214+
Self::BsonEncode(err)
215215
}
216216
}
217217

@@ -257,11 +257,11 @@ pub enum ErrorKind {
257257

258258
/// Wrapper around `bson::de::Error`.
259259
#[error("{0}")]
260-
BsonDecode(Arc<crate::bson::de::Error>),
260+
BsonDecode(crate::bson::de::Error),
261261

262262
/// Wrapper around `bson::ser::Error`.
263263
#[error("{0}")]
264-
BsonEncode(Arc<crate::bson::ser::Error>),
264+
BsonEncode(crate::bson::ser::Error),
265265

266266
/// An error occurred when trying to execute a write operation consisting of multiple writes.
267267
#[error("An error occurred when trying to execute a write operation: {0:?}")]

src/sdam/description/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl ServerDescription {
257257
.as_ref()
258258
.map_err(Clone::clone)?
259259
.as_ref()
260-
.and_then(|reply| reply.command_response.election_id.clone());
260+
.and_then(|reply| reply.command_response.election_id);
261261
Ok(me)
262262
}
263263

0 commit comments

Comments
 (0)