Skip to content

Commit 8e52cb7

Browse files
refactor: run clippy and clean the things
1 parent c9bfade commit 8e52cb7

File tree

8 files changed

+41
-43
lines changed

8 files changed

+41
-43
lines changed

mongod-derive/src/bson.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn impl_enum_struct(
116116
let mut #member: Option<#ty> = None;
117117
}
118118
});
119-
let values = v.fields.iter().map(|f| impl_struct_try_from_bson_field(&f));
119+
let values = v.fields.iter().map(|f| impl_struct_try_from_bson_field(f));
120120
let missing = v.fields.iter().map(|f| {
121121
let id = member_to_id(&f.member);
122122
let member = member_to_ident(&f.member);
@@ -353,7 +353,7 @@ fn impl_struct(
353353
let mut #member: Option<#ty> = None;
354354
}
355355
});
356-
let values = fields.iter().map(|f| impl_struct_try_from_bson_field(&f));
356+
let values = fields.iter().map(|f| impl_struct_try_from_bson_field(f));
357357
let missing = fields.iter().map(|f| {
358358
let id = member_to_id(&f.member);
359359
let member = &f.member;
@@ -411,7 +411,7 @@ fn impl_struct(
411411
fn impl_struct_try_from_bson_field(f: &Field) -> TokenStream {
412412
let member = member_to_ident(&f.member);
413413
let id = member_to_id(&f.member);
414-
let optional = is_option(&f.ty);
414+
let optional = is_option(f.ty);
415415
let ty = &f.ty;
416416
if f.attrs.serde {
417417
quote! {

mongod/src/async/client.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,10 @@ impl ClientBuilder {
246246
{
247247
let mut credentials = Credential::default();
248248
if self.username.is_some() || url.username() != "" {
249-
credentials.username = self.username.or(Some(url.username().to_string()));
250-
credentials.password = self.password.or(url.password().map(|p| p.to_string()));
249+
credentials.username = self.username.or_else(|| Some(url.username().to_string()));
250+
credentials.password = self
251+
.password
252+
.or_else(|| url.password().map(|p| p.to_string()));
251253
}
252254
if auth_source.is_some() {
253255
credentials.source = auth_source;
@@ -505,7 +507,7 @@ impl Client {
505507
if let Some(filter) = filter {
506508
delete = delete.filter::<F>(filter)?
507509
}
508-
delete.query(&self).await
510+
delete.query(self).await
509511
}
510512

511513
/// Convenience method to delete one document from a collection using a given filter.
@@ -521,7 +523,7 @@ impl Client {
521523
let deleted = query::Delete::<C>::new()
522524
.many(false)
523525
.filter::<F>(filter)?
524-
.query(&self)
526+
.query(self)
525527
.await?;
526528
Ok(deleted > 0)
527529
}
@@ -543,7 +545,7 @@ impl Client {
543545
if let Some(filter) = filter {
544546
find = find.filter(filter)?;
545547
}
546-
find.query(&self).await
548+
find.query(self).await
547549
}
548550

549551
/// Convenience method to find a document in a collection using a given filter.
@@ -561,7 +563,7 @@ impl Client {
561563
{
562564
// NOTE: We don't wanna make another builder so we just eat the cost of getting a cursor...
563565
let find: query::Find<C> = query::Find::new();
564-
let mut cursor = find.filter(filter)?.query(&self).await?;
566+
let mut cursor = find.filter(filter)?.query(self).await?;
565567
if let Some(res) = cursor.next().await {
566568
return Ok(Some(res?));
567569
}
@@ -577,7 +579,7 @@ impl Client {
577579
where
578580
C: Collection,
579581
{
580-
let result = query::Insert::new().query(&self, documents).await?;
582+
let result = query::Insert::new().query(self, documents).await?;
581583
Ok(result
582584
.into_iter()
583585
.filter_map(|(k, v)| match v {
@@ -597,11 +599,9 @@ impl Client {
597599
C: Collection,
598600
{
599601
// NOTE: We don't wanna make another builder so we just eat the cost of allocating a vec...
600-
let result = query::Insert::new().query(&self, vec![document]).await?;
601-
if let Some((_, v)) = result.into_iter().next() {
602-
if let bson::Bson::ObjectId(id) = v {
603-
return Ok(id);
604-
}
602+
let result = query::Insert::new().query(self, vec![document]).await?;
603+
if let Some((_, bson::Bson::ObjectId(id))) = result.into_iter().next() {
604+
return Ok(id);
605605
}
606606
Err(crate::error::mongodb(
607607
"failed to insert document into mongo",
@@ -620,7 +620,7 @@ impl Client {
620620
{
621621
query::Replace::new()
622622
.filter::<F>(filter)?
623-
.query(&self, document)
623+
.query(self, document)
624624
.await
625625
}
626626

@@ -637,7 +637,7 @@ impl Client {
637637
{
638638
let updated = query::Update::<C>::new()
639639
.filter::<F>(filter)?
640-
.query::<U>(&self, updates)
640+
.query::<U>(self, updates)
641641
.await?;
642642
Ok(updated)
643643
}
@@ -656,7 +656,7 @@ impl Client {
656656
let updated = query::Update::<C>::new()
657657
.many(false)
658658
.filter::<F>(filter)?
659-
.query::<U>(&self, updates)
659+
.query::<U>(self, updates)
660660
.await?;
661661
if updated > 0 {
662662
return Ok(true);
@@ -678,7 +678,7 @@ impl Client {
678678
let updated = query::Update::<C>::new()
679679
.upsert(true)
680680
.filter::<F>(filter)?
681-
.query::<U>(&self, updates)
681+
.query::<U>(self, updates)
682682
.await?;
683683
Ok(updated)
684684
}
@@ -698,7 +698,7 @@ impl Client {
698698
.many(false)
699699
.upsert(true)
700700
.filter::<F>(filter)?
701-
.query::<U>(&self, updates)
701+
.query::<U>(self, updates)
702702
.await?;
703703
if updated > 0 {
704704
return Ok(true);

mongod/src/async/cursor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
{
3535
fn from(cursor: mongodb::Cursor<Document>) -> Self {
3636
TypedCursor {
37-
cursor: cursor,
37+
cursor,
3838
document_type: PhantomData,
3939
}
4040
}

mongod/src/blocking/client.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl Client {
227227
if let Some(filter) = filter {
228228
delete = delete.filter(filter)?;
229229
}
230-
delete.blocking(&self)
230+
delete.blocking(self)
231231
}
232232

233233
/// Convenience method to delete one document from a collection using a given filter.
@@ -243,7 +243,7 @@ impl Client {
243243
let deleted = query::Delete::<C>::new()
244244
.many(false)
245245
.filter::<F>(filter)?
246-
.blocking(&self)?;
246+
.blocking(self)?;
247247
Ok(deleted > 0)
248248
}
249249

@@ -264,7 +264,7 @@ impl Client {
264264
if let Some(filter) = filter {
265265
find = find.filter(filter)?;
266266
}
267-
find.blocking(&self)
267+
find.blocking(self)
268268
}
269269

270270
/// Convenience method to find a document in a collection using a given filter.
@@ -282,7 +282,7 @@ impl Client {
282282
{
283283
// NOTE: We don't wanna make another builder so we just eat the cost of getting a cursor...
284284
let find: query::Find<C> = query::Find::new();
285-
let mut cursor = find.filter(filter)?.blocking(&self)?;
285+
let mut cursor = find.filter(filter)?.blocking(self)?;
286286
if let Some(res) = cursor.next() {
287287
return Ok(Some(res?));
288288
}
@@ -298,7 +298,7 @@ impl Client {
298298
where
299299
C: Collection,
300300
{
301-
let result = query::Insert::new().blocking(&self, documents)?;
301+
let result = query::Insert::new().blocking(self, documents)?;
302302
Ok(result
303303
.into_iter()
304304
.filter_map(|(k, v)| match v {
@@ -318,11 +318,9 @@ impl Client {
318318
C: Collection,
319319
{
320320
// NOTE: We don't wanna make another builder so we just eat the cost of allocating a vec...
321-
let result = query::Insert::new().blocking(&self, vec![document])?;
322-
if let Some((_, v)) = result.into_iter().next() {
323-
if let bson::Bson::ObjectId(id) = v {
324-
return Ok(id);
325-
}
321+
let result = query::Insert::new().blocking(self, vec![document])?;
322+
if let Some((_, bson::Bson::ObjectId(id))) = result.into_iter().next() {
323+
return Ok(id);
326324
}
327325
Err(crate::error::mongodb(
328326
"failed to insert document into mongo",
@@ -341,7 +339,7 @@ impl Client {
341339
{
342340
query::Replace::new()
343341
.filter::<F>(filter)?
344-
.blocking(&self, document)
342+
.blocking(self, document)
345343
}
346344

347345
/// Convenience method to update documents in a collection.
@@ -357,7 +355,7 @@ impl Client {
357355
{
358356
let updated = query::Update::<C>::new()
359357
.filter::<F>(filter)?
360-
.blocking::<U>(&self, updates)?;
358+
.blocking::<U>(self, updates)?;
361359
Ok(updated)
362360
}
363361

@@ -375,7 +373,7 @@ impl Client {
375373
let updated = query::Update::<C>::new()
376374
.many(false)
377375
.filter::<F>(filter)?
378-
.blocking::<U>(&self, updates)?;
376+
.blocking::<U>(self, updates)?;
379377
if updated > 0 {
380378
return Ok(true);
381379
}
@@ -396,7 +394,7 @@ impl Client {
396394
let updated = query::Update::<C>::new()
397395
.upsert(true)
398396
.filter::<F>(filter)?
399-
.blocking::<U>(&self, updates)?;
397+
.blocking::<U>(self, updates)?;
400398
Ok(updated)
401399
}
402400

@@ -415,7 +413,7 @@ impl Client {
415413
.many(false)
416414
.upsert(true)
417415
.filter::<F>(filter)?
418-
.blocking::<U>(&self, updates)?;
416+
.blocking::<U>(self, updates)?;
419417
if updated > 0 {
420418
return Ok(true);
421419
}

mongod/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl fmt::Display for Error {
8080
if let Some(ref source) = self.inner.source {
8181
write!(f, "{}: {}", desc, source)
8282
} else {
83-
f.write_str(&desc)
83+
f.write_str(desc)
8484
}
8585
}
8686
}

mongod/src/ext/bson.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ where
186186
type Error = de::Error;
187187
fn try_from(value: Bson) -> Result<Self, Self::Error> {
188188
Ok(De(
189-
bson::from_bson(value.0).map_err(|e| bson::de::Error::custom(e))?
189+
bson::from_bson(value.0).map_err(bson::de::Error::custom)?
190190
))
191191
}
192192
}
@@ -198,7 +198,7 @@ where
198198
type Error = ser::Error;
199199
fn try_from(value: Ser<T>) -> Result<Self, Self::Error> {
200200
Ok(Bson(
201-
bson::to_bson(&value.0).map_err(|e| bson::ser::Error::custom(e))?,
201+
bson::to_bson(&value.0).map_err(bson::ser::Error::custom)?,
202202
))
203203
}
204204
}

mongod/src/query/find.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<C: Collection> Find<C> {
258258
.collection::<Document>(C::COLLECTION)
259259
.find(self.filter, self.options)
260260
.await
261-
.map(|cur| TypedCursor::from(cur))
261+
.map(TypedCursor::from)
262262
.map_err(crate::error::mongodb)
263263
}
264264

mongod/src/sort.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ where
1616
Nested(Sort<T>),
1717
}
1818

19-
impl<T> Into<Bson> for Order<T>
19+
impl<T> From<Order<T>> for Bson
2020
where
2121
T: Field + Into<String>,
2222
{
23-
fn into(self) -> Bson {
24-
match self {
23+
fn from(order: Order<T>) -> Self {
24+
match order {
2525
// Mongo uses '1' and '-1' to denote sort order in the document
2626
// given to queries' '$sort' property
2727
Order::Asc => Bson::Int32(1),

0 commit comments

Comments
 (0)