1
1
mod batch;
2
2
pub mod options;
3
3
4
- use std:: { fmt, fmt:: Debug , sync:: Arc } ;
4
+ use std:: { borrow :: Borrow , fmt, fmt:: Debug , sync:: Arc } ;
5
5
6
6
use futures:: StreamExt ;
7
7
use serde:: {
@@ -539,11 +539,11 @@ where
539
539
async fn find_one_and_replace_common (
540
540
& self ,
541
541
filter : Document ,
542
- replacement : T ,
542
+ replacement : impl Borrow < T > ,
543
543
options : impl Into < Option < FindOneAndReplaceOptions > > ,
544
544
session : impl Into < Option < & mut ClientSession > > ,
545
545
) -> Result < Option < T > > {
546
- let replacement = to_document ( & replacement) ?;
546
+ let replacement = to_document ( replacement. borrow ( ) ) ?;
547
547
548
548
let mut options = options. into ( ) ;
549
549
resolve_options ! ( self , options, [ write_concern] ) ;
@@ -562,7 +562,7 @@ where
562
562
pub async fn find_one_and_replace (
563
563
& self ,
564
564
filter : Document ,
565
- replacement : T ,
565
+ replacement : impl Borrow < T > ,
566
566
options : impl Into < Option < FindOneAndReplaceOptions > > ,
567
567
) -> Result < Option < T > > {
568
568
self . find_one_and_replace_common ( filter, replacement, options, None )
@@ -579,7 +579,7 @@ where
579
579
pub async fn find_one_and_replace_with_session (
580
580
& self ,
581
581
filter : Document ,
582
- replacement : T ,
582
+ replacement : impl Borrow < T > ,
583
583
options : impl Into < Option < FindOneAndReplaceOptions > > ,
584
584
session : & mut ClientSession ,
585
585
) -> Result < Option < T > > {
@@ -643,13 +643,13 @@ where
643
643
644
644
async fn insert_many_common (
645
645
& self ,
646
- docs : impl IntoIterator < Item = T > ,
646
+ docs : impl IntoIterator < Item = impl Borrow < T > > ,
647
647
options : impl Into < Option < InsertManyOptions > > ,
648
648
mut session : Option < & mut ClientSession > ,
649
649
) -> Result < InsertManyResult > {
650
650
let docs: ser:: Result < Vec < Document > > = docs
651
651
. into_iter ( )
652
- . map ( |doc| bson:: to_document ( & doc) )
652
+ . map ( |doc| bson:: to_document ( doc. borrow ( ) ) )
653
653
. collect ( ) ;
654
654
let mut docs: Vec < Document > = docs?;
655
655
@@ -739,7 +739,7 @@ where
739
739
/// retryable writes.
740
740
pub async fn insert_many (
741
741
& self ,
742
- docs : impl IntoIterator < Item = T > ,
742
+ docs : impl IntoIterator < Item = impl Borrow < T > > ,
743
743
options : impl Into < Option < InsertManyOptions > > ,
744
744
) -> Result < InsertManyResult > {
745
745
self . insert_many_common ( docs, options, None ) . await
@@ -753,7 +753,7 @@ where
753
753
/// retryable writes.
754
754
pub async fn insert_many_with_session (
755
755
& self ,
756
- docs : impl IntoIterator < Item = T > ,
756
+ docs : impl IntoIterator < Item = impl Borrow < T > > ,
757
757
options : impl Into < Option < InsertManyOptions > > ,
758
758
session : & mut ClientSession ,
759
759
) -> Result < InsertManyResult > {
@@ -762,11 +762,11 @@ where
762
762
763
763
async fn insert_one_common (
764
764
& self ,
765
- doc : T ,
765
+ doc : impl Borrow < T > ,
766
766
options : impl Into < Option < InsertOneOptions > > ,
767
767
session : impl Into < Option < & mut ClientSession > > ,
768
768
) -> Result < InsertOneResult > {
769
- let doc = to_document ( & doc) ?;
769
+ let doc = to_document ( doc. borrow ( ) ) ?;
770
770
771
771
let mut options = options. into ( ) ;
772
772
resolve_options ! ( self , options, [ write_concern] ) ;
@@ -791,7 +791,7 @@ where
791
791
/// retryable writes.
792
792
pub async fn insert_one (
793
793
& self ,
794
- doc : T ,
794
+ doc : impl Borrow < T > ,
795
795
options : impl Into < Option < InsertOneOptions > > ,
796
796
) -> Result < InsertOneResult > {
797
797
self . insert_one_common ( doc, options, None ) . await
@@ -805,7 +805,7 @@ where
805
805
/// retryable writes.
806
806
pub async fn insert_one_with_session (
807
807
& self ,
808
- doc : T ,
808
+ doc : impl Borrow < T > ,
809
809
options : impl Into < Option < InsertOneOptions > > ,
810
810
session : & mut ClientSession ,
811
811
) -> Result < InsertOneResult > {
@@ -815,11 +815,11 @@ where
815
815
async fn replace_one_common (
816
816
& self ,
817
817
query : Document ,
818
- replacement : T ,
818
+ replacement : impl Borrow < T > ,
819
819
options : impl Into < Option < ReplaceOptions > > ,
820
820
session : impl Into < Option < & mut ClientSession > > ,
821
821
) -> Result < UpdateResult > {
822
- let replacement = to_document ( & replacement) ?;
822
+ let replacement = to_document ( replacement. borrow ( ) ) ?;
823
823
824
824
bson_util:: replacement_document_check ( & replacement) ?;
825
825
@@ -845,7 +845,7 @@ where
845
845
pub async fn replace_one (
846
846
& self ,
847
847
query : Document ,
848
- replacement : T ,
848
+ replacement : impl Borrow < T > ,
849
849
options : impl Into < Option < ReplaceOptions > > ,
850
850
) -> Result < UpdateResult > {
851
851
self . replace_one_common ( query, replacement, options, None )
@@ -862,7 +862,7 @@ where
862
862
pub async fn replace_one_with_session (
863
863
& self ,
864
864
query : Document ,
865
- replacement : T ,
865
+ replacement : impl Borrow < T > ,
866
866
options : impl Into < Option < ReplaceOptions > > ,
867
867
session : & mut ClientSession ,
868
868
) -> Result < UpdateResult > {
0 commit comments